[tracker/wip/carlosg/sparql1.1: 18/113] libtracker-data: Add vmethod to update interfaces after attached db changes



commit a5fde2b4069493bf7a89effa086621feaa9e3423
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Jun 3 01:38:40 2019 +0200

    libtracker-data: Add vmethod to update interfaces after attached db changes
    
    This will be necessary to update the union views after graph databases are
    created and destroyed.

 src/libtracker-data/tracker-data-manager.c | 71 ++++++++++++++++++++++++++++++
 src/libtracker-data/tracker-db-manager.c   | 13 +++++-
 2 files changed, 83 insertions(+), 1 deletion(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 0f0788ab7..668c1edb3 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -86,6 +86,7 @@ struct _TrackerDataManager {
        GHashTable *graphs;
 
        gchar *status;
+       guint64 cache_mtime;
 };
 
 struct _TrackerDataManagerClass {
@@ -4107,6 +4108,57 @@ setup_interface_cb (TrackerDBManager   *db_manager,
        }
 }
 
+static void
+update_interface_cb (TrackerDBManager   *db_manager,
+                     TrackerDBInterface *iface,
+                     TrackerDataManager *data_manager)
+{
+       GError *error = NULL;
+       guint64 cache_mtime;
+       gchar *cache_dir;
+
+       cache_dir = g_file_get_path (data_manager->cache_location);
+       cache_mtime = tracker_file_get_mtime (cache_dir);
+
+       if (cache_mtime > data_manager->cache_mtime) {
+               GHashTable *graphs;
+
+               graphs = data_manager->graphs;
+               data_manager->graphs = NULL;
+
+               tracker_data_manager_ensure_graphs (data_manager, iface, NULL);
+
+               if (data_manager->graphs) {
+                       GHashTableIter iter;
+                       gpointer value;
+                       GError *error = NULL;
+
+                       g_hash_table_iter_init (&iter, data_manager->graphs);
+
+                       while (g_hash_table_iter_next (&iter, &value, NULL)) {
+                               if (g_hash_table_contains (graphs, value))
+                                       continue;
+
+                               if (!tracker_db_manager_attach_database (db_manager,
+                                                                        iface, value, FALSE,
+                                                                        &error)) {
+                                       g_critical ("Could not attach database '%s': %s\n",
+                                                   (gchar *) value, error->message);
+                                       g_clear_error (&error);
+                                       continue;
+                               }
+                       }
+               }
+
+               if (!tracker_data_manager_update_union_views (data_manager, iface, &error)) {
+                       g_critical ("Could not update union views: %s\n", error->message);
+                       g_error_free (error);
+               }
+       }
+
+       data_manager->cache_mtime = cache_mtime;
+}
+
 static gboolean
 tracker_data_manager_initable_init (GInitable     *initable,
                                     GCancellable  *cancellable,
@@ -4163,6 +4215,8 @@ tracker_data_manager_initable_init (GInitable     *initable,
 
        g_signal_connect (manager->db_manager, "setup-interface",
                          G_CALLBACK (setup_interface_cb), manager);
+       g_signal_connect (manager->db_manager, "update-interface",
+                         G_CALLBACK (update_interface_cb), manager);
 
        manager->first_time_index = is_first_time_index;
 
@@ -4242,6 +4296,9 @@ tracker_data_manager_initable_init (GInitable     *initable,
                tracker_data_manager_init_fts (iface, TRUE);
 #endif
 
+               // FIXME
+               setup_interface_cb (manager->db_manager, iface, manager);
+
                /* store ontology in database */
                for (l = sorted; l; l = l->next) {
                        import_ontology_file (manager, l->data, FALSE);
@@ -4294,6 +4351,9 @@ tracker_data_manager_initable_init (GInitable     *initable,
 #if HAVE_TRACKER_FTS
                tracker_data_manager_init_fts (iface, FALSE);
 #endif
+
+               // FIXME: a bit hackish
+               setup_interface_cb (manager->db_manager, iface, manager);
        }
 
        if (!read_only) {
@@ -4725,6 +4785,9 @@ skip_ontology_check:
                tracker_ontologies_sort (manager->ontologies);
        }
 
+       // FIXME: a bit hackish
+       manager->cache_mtime = tracker_file_get_mtime (g_file_get_path (manager->cache_location));
+
        manager->initialized = TRUE;
 
        /* This is the only one which doesn't show the 'OPERATION' part */
@@ -4943,6 +5006,7 @@ tracker_data_manager_create_graph (TrackerDataManager  *manager,
        TrackerDBInterface *iface;
        gint id;
 
+
        iface = tracker_db_manager_get_writable_db_interface (manager->db_manager);
 
        if (!tracker_db_manager_attach_database (manager->db_manager, iface,
@@ -4958,6 +5022,10 @@ tracker_data_manager_create_graph (TrackerDataManager  *manager,
                goto detach;
 
        g_hash_table_insert (manager->graphs, g_strdup (name), GINT_TO_POINTER (id));
+
+       if (!tracker_data_manager_update_union_views (manager, iface, error))
+               goto detach;
+
        return TRUE;
 
 detach:
@@ -4989,6 +5057,9 @@ tracker_data_manager_drop_graph (TrackerDataManager  *manager,
        if (!tracker_data_delete_graph (manager->data_update, name, error))
                return FALSE;
 
+       if (!tracker_data_manager_update_union_views (manager, iface, error))
+               return FALSE;
+
        if (manager->graphs)
                g_hash_table_remove (manager->graphs, name);
 
diff --git a/src/libtracker-data/tracker-db-manager.c b/src/libtracker-data/tracker-db-manager.c
index bc1997127..63986d458 100644
--- a/src/libtracker-data/tracker-db-manager.c
+++ b/src/libtracker-data/tracker-db-manager.c
@@ -150,6 +150,7 @@ struct _TrackerDBManager {
 
 enum {
        SETUP_INTERFACE,
+       UPDATE_INTERFACE,
        N_SIGNALS
 };
 
@@ -1066,7 +1067,9 @@ tracker_db_manager_get_db_interface (TrackerDBManager *db_manager)
                interface = NULL;
        }
 
-       if (!interface) {
+       if (interface) {
+               g_signal_emit (db_manager, signals[UPDATE_INTERFACE], 0, interface);
+       } else {
                /* Create a new one to satisfy the request */
                interface = tracker_db_manager_create_db_interface (db_manager,
                                                                    TRUE, &internal_error);
@@ -1113,6 +1116,14 @@ tracker_db_manager_class_init (TrackerDBManagerClass *klass)
                              g_cclosure_marshal_VOID__OBJECT,
                              G_TYPE_NONE,
                              1, TRACKER_TYPE_DB_INTERFACE);
+       signals[UPDATE_INTERFACE] =
+               g_signal_new ("update-interface",
+                             G_TYPE_FROM_CLASS (klass),
+                             G_SIGNAL_RUN_LAST, 0,
+                             NULL, NULL,
+                             g_cclosure_marshal_VOID__OBJECT,
+                             G_TYPE_NONE,
+                             1, TRACKER_TYPE_DB_INTERFACE);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]