[gnome-photos/wip/rishi/online-miners: 9/14] tracker-queue: Add a second TrackerSparqlConnection for remote content




commit 9745c9a7e530a3699df8d4d63f62a1c69515ea4c
Author: Debarshi Ray <debarshir gnome org>
Date:   Sun Apr 4 00:54:17 2021 +0200

    tracker-queue: Add a second TrackerSparqlConnection for remote content
    
    The user-generated metadata stored in ~/.local/share/gnome-photos needs
    to be stored persistently because it's the canonical source for it.
    
    However, the metadata for remote items merely needs to be cached, and
    can be regenerated at ease from the corresponding online sources.
    Therefore, it's worth using a separate database for it that will be
    populated by the online miners. This will shield the user-generated
    metadata from getting corrupted by a bug in the online miners.
    
    https://gitlab.gnome.org/GNOME/gnome-photos/-/issues/83

 src/photos-tracker-queue.c | 30 +++++++++++++++++++++++++++++-
 src/photos-tracker-queue.h |  2 ++
 2 files changed, 31 insertions(+), 1 deletion(-)
---
diff --git a/src/photos-tracker-queue.c b/src/photos-tracker-queue.c
index a0f93dc2..f27ae336 100644
--- a/src/photos-tracker-queue.c
+++ b/src/photos-tracker-queue.c
@@ -36,6 +36,7 @@ struct _PhotosTrackerQueue
   GObject parent_instance;
   GError *initialization_error;
   GQueue *queue;
+  TrackerSparqlConnection *connection_online;
   TrackerSparqlConnection *connection_private;
   gboolean is_initialized;
   gboolean running;
@@ -231,6 +232,7 @@ photos_tracker_queue_dispose (GObject *object)
 {
   PhotosTrackerQueue *self = PHOTOS_TRACKER_QUEUE (object);
 
+  g_clear_object (&self->connection_online);
   g_clear_object (&self->connection_private);
 
   G_OBJECT_CLASS (photos_tracker_queue_parent_class)->dispose (object);
@@ -272,17 +274,20 @@ photos_tracker_queue_initable_init (GInitable *initable, GCancellable *cancellab
 {
   PhotosTrackerQueue *self = PHOTOS_TRACKER_QUEUE (initable);
   g_autoptr (GFile) ontology = NULL;
+  g_autoptr (GFile) store_online = NULL;
   g_autoptr (GFile) store_private = NULL;
   TrackerSparqlConnectionFlags tracker_flags;
   gboolean ret_val = FALSE;
+  const gchar *cache_dir;
   const gchar *data_dir;
+  const gchar *store_online_path;
   const gchar *store_private_path;
 
   G_LOCK (init_lock);
 
   if (self->is_initialized)
     {
-      if (self->connection_private != NULL)
+      if (self->connection_online != NULL && self->connection_private != NULL)
         ret_val = TRUE;
       else
         g_assert_nonnull (self->initialization_error);
@@ -303,6 +308,20 @@ photos_tracker_queue_initable_init (GInitable *initable, GCancellable *cancellab
                   | TRACKER_SPARQL_CONNECTION_FLAGS_FTS_ENABLE_UNACCENT
                   | TRACKER_SPARQL_CONNECTION_FLAGS_FTS_IGNORE_NUMBERS;
 
+  cache_dir = g_get_user_cache_dir ();
+  store_online = g_file_new_build_filename (cache_dir, PACKAGE_TARNAME, "tracker3", "online", NULL);
+  store_online_path = g_file_peek_path (store_online);
+
+  photos_debug (PHOTOS_DEBUG_TRACKER, "Opening online database at %s", store_online_path);
+
+  self->connection_online = tracker_sparql_connection_new (tracker_flags,
+                                                           store_online,
+                                                           ontology,
+                                                           cancellable,
+                                                           &self->initialization_error);
+  if (G_UNLIKELY (self->initialization_error != NULL))
+    goto out;
+
   data_dir = g_get_user_data_dir ();
   store_private = g_file_new_build_filename (data_dir, PACKAGE_TARNAME, "tracker3", "private", NULL);
   store_private_path = g_file_peek_path (store_private);
@@ -317,6 +336,7 @@ photos_tracker_queue_initable_init (GInitable *initable, GCancellable *cancellab
   if (G_UNLIKELY (self->initialization_error != NULL))
     goto out;
 
+  tracker_sparql_connection_map_connection (self->connection_private, "online", self->connection_online);
   ret_val = TRUE;
 
  out:
@@ -361,6 +381,14 @@ photos_tracker_queue_create_notifier (PhotosTrackerQueue *self)
 }
 
 
+TrackerSparqlConnection *
+photos_tracker_queue_get_connection_online (PhotosTrackerQueue *self)
+{
+  g_return_val_if_fail (PHOTOS_IS_TRACKER_QUEUE (self), NULL);
+  return self->connection_online;
+}
+
+
 void
 photos_tracker_queue_select (PhotosTrackerQueue *self,
                              PhotosQuery *query,
diff --git a/src/photos-tracker-queue.h b/src/photos-tracker-queue.h
index 732ea03b..3ba6745d 100644
--- a/src/photos-tracker-queue.h
+++ b/src/photos-tracker-queue.h
@@ -37,6 +37,8 @@ PhotosTrackerQueue    *photos_tracker_queue_dup_singleton          (GCancellable
 
 TrackerNotifier       *photos_tracker_queue_create_notifier        (PhotosTrackerQueue *self);
 
+TrackerSparqlConnection *photos_tracker_queue_get_connection_online (PhotosTrackerQueue *self);
+
 void                   photos_tracker_queue_select                 (PhotosTrackerQueue *self,
                                                                     PhotosQuery *query,
                                                                     GCancellable *cancellable,


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