Bug 445336 - Resource system doesn't purge resources whose storage has been removed
Summary: Resource system doesn't purge resources whose storage has been removed
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Resource Management (show other bugs)
Version: 5.0.0-beta2
Platform: Microsoft Windows Microsoft Windows
: NOR normal
Target Milestone: ---
Assignee: amyspark
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-11-11 14:01 UTC by amyspark
Modified: 2021-11-16 15:56 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description amyspark 2021-11-11 14:01:49 UTC
SUMMARY

The resource system does not remove resources from the database on removal of their storage. This means that a call to KisResourceLocator::instance()->addStorage(newLocation, storage), even with a previous call to KisResourceLocator::instance()->removeStorage(newLocation), will yield a spam of the following:

> Could not execute tagResource statement QMap((":resource_id", QVariant(int, 1520))(":tag_id", QVariant(int, 16))) QSqlError("19", "Unable to fetch row", "UNIQUE constraint failed: resource_tags.tag_id, resource_tags.resource_id")
> Could not tag resource "qs_b_waterink" from "Quiraltas_SM_Brush_Set.bundle" filename "qs_b_waterink.kpp" with tag "Quiralta"

This is visually reflected (if the removeStorage call is made) with multiple entries of the same bundle in the Bundle Manager.

STEPS TO REPRODUCE
1.  Import a bundle.
2.  Try to import the bundle again.

OBSERVED RESULT

Multiple entries of the same bundle.

EXPECTED RESULT

A single entry of the bundle and no errors on import.
SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
ee19ed32f1 (upstream/krita/5.0, krita/5.0) Make sure the new name of the preset is visible after editing.
Comment 1 Halla Rempt 2021-11-11 14:13:58 UTC
I'm pretty sure this used to work...
Comment 2 amyspark 2021-11-11 19:20:00 UTC
No, in d032070993d45cca216c7f8c319eac65e4253aea it seems you forgot to account for storage deletion. It was also overlooked on abe84bc3c63a290e79525a0021fa11b4cb05926, so every time one tried to add a tag whose storage was deleted, the uniqueness constraints would fail.
Comment 3 amyspark 2021-11-16 15:54:58 UTC
Git commit 4d70fed5adcf1fbdf657e278a70e12e1ec1db0b6 by L. E. Segovia.
Committed on 16/11/2021 at 15:53.
Pushed by lsegovia into branch 'krita/5.0'.

Fix repeated imports of the same bundle resource

Half of this fix is to make sure all import paths copy bundles to the
root data folder.

The other half is to ensure tags and resource-tags relationships are
completely purged when the backing bundle is gone.

M  +37   -0    libs/resources/KisResourceCacheDb.cpp
M  +2    -2    libs/ui/KisMainWindow.cpp
M  +2    -1    plugins/extensions/resourcemanager/dlg_bundle_manager.cpp

https://invent.kde.org/graphics/krita/commit/4d70fed5adcf1fbdf657e278a70e12e1ec1db0b6
Comment 4 amyspark 2021-11-16 15:56:16 UTC
Git commit ff8b91ad787c53d42e869cec8cec8db3fae7fb96 by L. E. Segovia.
Committed on 16/11/2021 at 15:55.
Pushed by lsegovia into branch 'master'.

Fix repeated imports of the same bundle resource

Half of this fix is to make sure all import paths copy bundles to the
root data folder.

The other half is to ensure tags and resource-tags relationships are
completely purged when the backing bundle is gone.
(cherry picked from commit 4d70fed5adcf1fbdf657e278a70e12e1ec1db0b6)

M  +37   -0    libs/resources/KisResourceCacheDb.cpp
M  +2    -2    libs/ui/KisMainWindow.cpp
M  +2    -1    plugins/extensions/resourcemanager/dlg_bundle_manager.cpp

https://invent.kde.org/graphics/krita/commit/ff8b91ad787c53d42e869cec8cec8db3fae7fb96