[tracker/wip/carlosg/graphs-through-with: 12/15] libtracker-data: Make inline union of all Refcount tables
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/graphs-through-with: 12/15] libtracker-data: Make inline union of all Refcount tables
- Date: Tue, 10 Dec 2019 12:43:24 +0000 (UTC)
commit d760669a6dbdca243a719eddb77bf3538e706911
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Nov 23 20:14:29 2019 +0100
libtracker-data: Make inline union of all Refcount tables
We don't need a temporary view just for this.
src/libtracker-data/tracker-data-manager.c | 98 ++++++++++++++----------------
1 file changed, 45 insertions(+), 53 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 699fda2aa..b6632b0a1 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -4905,61 +4905,65 @@ skip_ontology_check:
}
static gboolean
-data_manager_check_perform_cleanup (TrackerDataManager *manager)
+data_manager_perform_cleanup (TrackerDataManager *manager,
+ TrackerDBInterface *iface,
+ GError **error)
{
TrackerDBStatement *stmt;
- TrackerDBInterface *iface;
- TrackerDBCursor *cursor = NULL;
- guint count = 0;
-
- iface = tracker_db_manager_get_writable_db_interface (manager->db_manager);
- stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_NONE,
- NULL, "SELECT COUNT(*) FROM Graph");
- if (stmt) {
- cursor = tracker_db_statement_start_cursor (stmt, NULL);
- g_object_unref (stmt);
- }
+ GError *internal_error = NULL;
+ GHashTable *graphs;
+ GHashTableIter iter;
+ const gchar *graph;
+ GString *str;
- if (cursor && tracker_db_cursor_iter_next (cursor, NULL, NULL))
- count = tracker_db_cursor_get_int (cursor, 0);
+ str = g_string_new ("WITH referencedElements(ID) AS ("
+ "SELECT ID FROM \"main\".Refcount ");
- g_clear_object (&cursor);
+ graphs = tracker_data_manager_ensure_graphs (manager, iface, &internal_error);
+ if (!graphs)
+ goto fail;
- /* We need to be sure the data is coherent, so we'll refrain from
- * doing any clean ups till there are elements in the Graph table.
- *
- * A database that's been freshly updated to the refcounted
- * resources will have an empty Graph table, so we might
- * unintentionally delete graph URNs if we clean up in this state.
- */
- if (count == 0)
- return FALSE;
+ g_hash_table_iter_init (&iter, graphs);
- count = 0;
- stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_NONE, NULL,
- "SELECT COUNT(*) FROM Resource "
- "WHERE Resource.ID > %d "
- "AND Resource.ID NOT IN (SELECT ROWID FROM
unionGraph_Refcount) "
- "AND Resource.ID NOT IN (SELECT ID FROM Graph)",
- TRACKER_ONTOLOGIES_MAX_ID);
- if (stmt) {
- cursor = tracker_db_statement_start_cursor (stmt, NULL);
- g_object_unref (stmt);
+ while (g_hash_table_iter_next (&iter, (gpointer*) &graph, NULL)) {
+ g_string_append_printf (str,
+ "UNION ALL SELECT ID FROM \"%s\".Refcount ",
+ graph);
}
- if (cursor && tracker_db_cursor_iter_next (cursor, NULL, NULL))
- count = tracker_db_cursor_get_int (cursor, 0);
+ g_string_append (str, ") ");
+ g_string_append_printf (str,
+ "DELETE FROM Resource "
+ "WHERE Resource.ID > %d "
+ "AND Resource.ID NOT IN (SELECT ID FROM referencedElements) "
+ "AND Resource.ID NOT IN (SELECT ID FROM Graph)",
+ TRACKER_ONTOLOGIES_MAX_ID);
+
+ stmt = tracker_db_interface_create_statement (iface,
+ TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE,
+ &internal_error,
+ "%s", str->str);
+ g_string_free (str, TRUE);
+
+ if (!stmt)
+ goto fail;
+
+ tracker_db_statement_execute (stmt, &internal_error);
+ g_object_unref (stmt);
- g_clear_object (&cursor);
+fail:
+ if (internal_error) {
+ g_propagate_error (error, internal_error);
+ return FALSE;
+ }
- return count > 0;
+ return TRUE;
}
void
tracker_data_manager_dispose (GObject *object)
{
TrackerDataManager *manager = TRACKER_DATA_MANAGER (object);
- TrackerDBStatement *stmt;
TrackerDBInterface *iface;
GError *error = NULL;
gboolean readonly = TRUE;
@@ -4967,25 +4971,13 @@ tracker_data_manager_dispose (GObject *object)
if (manager->db_manager) {
readonly = (tracker_db_manager_get_flags (manager->db_manager, NULL, NULL) &
TRACKER_DB_MANAGER_READONLY) != 0;
- if (!readonly && data_manager_check_perform_cleanup (manager)) {
+ if (!readonly) {
/* Delete stale URIs in the Resource table */
g_debug ("Cleaning up stale resource URIs");
iface = tracker_db_manager_get_writable_db_interface (manager->db_manager);
- stmt = tracker_db_interface_create_statement (iface,
TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE,
- &error,
- "DELETE FROM Resource "
- "WHERE Resource.ID > %d "
- "AND Resource.ID NOT IN (SELECT ROWID
FROM unionGraph_Refcount) "
- "AND Resource.ID NOT IN (SELECT ID FROM
Graph)",
- TRACKER_ONTOLOGIES_MAX_ID);
-
- if (stmt) {
- tracker_db_statement_execute (stmt, &error);
- g_object_unref (stmt);
- }
- if (error) {
+ if (!data_manager_perform_cleanup (manager, iface, &error)) {
g_warning ("Could not clean up stale resource URIs: %s\n",
error->message);
g_clear_error (&error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]