Bug 445336

Summary: Resource system doesn't purge resources whose storage has been removed
Product: [Applications] krita Reporter: amyspark <amy>
Component: Resource ManagementAssignee: amyspark <amy>
Status: RESOLVED FIXED    
Severity: normal CC: halla
Priority: NOR    
Version: 5.0.0-beta2   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed In:

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