Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Add a warning when orphaned metadata is found

Dmitry Kazakov834914ff8b2f
diff --git a/libs/resources/KisResourceCacheDb.cpp b/libs/resources/KisResourceCacheDb.cpp
index 1183505e3c..fbda5e2b32 100644
--- a/libs/resources/KisResourceCacheDb.cpp
+++ b/libs/resources/KisResourceCacheDb.cpp
@@ -2090,7 +2090,6 @@ bool KisResourceCacheDb::synchronizeStorage(KisResourceStorageSP storage)
QSqlDatabase::database().commit();
- removeOrphanedMetaData();
debugResource << "Synchronizing the storages took" << t.elapsed() << "milliseconds for" << storage->location();
return success;
@@ -2346,6 +2345,11 @@ bool KisResourceCacheDb::removeOrphanedMetaData()
return false;
}
+
+ if (q.numRowsAffected() > 0) {
+ qWarning() << "WARNING: orphaned metadata records were found for the resources! Num records removed:"
+ << q.numRowsAffected();
+ }
}
{
@@ -2363,7 +2367,10 @@ bool KisResourceCacheDb::removeOrphanedMetaData()
QSqlDatabase::database().rollback();
qWarning() << "Could not execute delete oprhaned metadata query for storages" << q.lastError();
return false;
-
+ }
+ if (q.numRowsAffected() > 0) {
+ qWarning() << "WARNING: orphaned metadata records were found for the storages! Num records removed:"
+ << q.numRowsAffected();
}
}
QSqlDatabase::database().commit();
diff --git a/libs/resources/KisResourceLocator.cpp b/libs/resources/KisResourceLocator.cpp
index 4c8edb834f..8f0fe46b6d 100644
--- a/libs/resources/KisResourceLocator.cpp
+++ b/libs/resources/KisResourceLocator.cpp
@@ -1216,6 +1216,16 @@ bool KisResourceLocator::synchronizeDb()
}
}
+ /**
+ * In the current layout of the database we cannot set FOREIGN KEY
+ * for the metadata table (since it links to both, resources and storages),
+ * hence we should manually track the orphaned data.
+ *
+ * Theoretically, these should be none, if our code is correct, but who
+ * knows anything about our code...
+ */
+ KisResourceCacheDb::removeOrphanedMetaData();
+
// now remove the storages that no longer exists
KisStorageModel model;