[gnome-photos/wip/rishi/collection: 13/16] Use Query objects instead of raw strings in the TrackerQueue API



commit 39dfdc5cef15d72f741e4de94cdc17c34fa0fea8
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Sep 4 16:13:48 2017 +0200

    Use Query objects instead of raw strings in the TrackerQueue API
    
    This will enable more human-readable logging of the Tracker queries by
    annotating the SPARQL strings with a description of who initiated them
    and under what circumstances.

 src/photos-camera-cache.c            |    2 +-
 src/photos-collection-icon-watcher.c |    2 +-
 src/photos-create-collection-job.c   |    2 +-
 src/photos-delete-item-job.c         |    2 +-
 src/photos-fetch-collections-job.c   |    2 +-
 src/photos-fetch-ids-job.c           |    2 +-
 src/photos-offset-controller.c       |    2 +-
 src/photos-properties-dialog.c       |    2 +-
 src/photos-set-collection-job.c      |    2 +-
 src/photos-single-item-job.c         |    2 +-
 src/photos-tracker-change-monitor.c  |    7 ++++++-
 src/photos-tracker-controller.c      |    2 +-
 src/photos-tracker-queue.c           |   12 ++++++------
 src/photos-tracker-queue.h           |    8 +++++---
 src/photos-update-mtime-job.c        |    2 +-
 src/photos-utils.c                   |   12 ++++++++++--
 16 files changed, 39 insertions(+), 24 deletions(-)
---
diff --git a/src/photos-camera-cache.c b/src/photos-camera-cache.c
index 5b5614a..8a3bf40 100644
--- a/src/photos-camera-cache.c
+++ b/src/photos-camera-cache.c
@@ -228,7 +228,7 @@ photos_camera_cache_get_camera_async (PhotosCameraCache *self,
 
   query = photos_query_builder_equipment_query (state, id);
   photos_tracker_queue_select (self->queue,
-                               query->sparql,
+                               query,
                                cancellable,
                                photos_camera_cache_equipment_query_executed,
                                g_object_ref (task),
diff --git a/src/photos-collection-icon-watcher.c b/src/photos-collection-icon-watcher.c
index 167d156..dff1928 100644
--- a/src/photos-collection-icon-watcher.c
+++ b/src/photos-collection-icon-watcher.c
@@ -345,7 +345,7 @@ photos_collection_icon_watcher_start (PhotosCollectionIconWatcher *self)
   id = photos_filterable_get_id (PHOTOS_FILTERABLE (self->collection));
   query = photos_query_builder_collection_icon_query (state, id);
   photos_tracker_queue_select (self->queue,
-                               query->sparql,
+                               query,
                                NULL,
                                photos_collection_icon_watcher_query_executed,
                                g_object_ref (self),
diff --git a/src/photos-create-collection-job.c b/src/photos-create-collection-job.c
index 50712e4..bf3f8e9 100644
--- a/src/photos-create-collection-job.c
+++ b/src/photos-create-collection-job.c
@@ -219,7 +219,7 @@ photos_create_collection_job_run (PhotosCreateCollectionJob *self,
 
   query = photos_query_builder_create_collection_query (state, self->name);
   photos_tracker_queue_update_blank (self->queue,
-                                     query->sparql,
+                                     query,
                                      cancellable,
                                      photos_create_collection_job_query_executed,
                                      g_object_ref (task),
diff --git a/src/photos-delete-item-job.c b/src/photos-delete-item-job.c
index 85d6340..98eb796 100644
--- a/src/photos-delete-item-job.c
+++ b/src/photos-delete-item-job.c
@@ -185,7 +185,7 @@ photos_delete_item_job_run (PhotosDeleteItemJob *self,
 
   query = photos_query_builder_delete_resource_query (state, self->urn);
   photos_tracker_queue_update (self->queue,
-                               query->sparql,
+                               query,
                                NULL,
                                photos_delete_item_job_query_executed,
                                g_object_ref (task),
diff --git a/src/photos-fetch-collections-job.c b/src/photos-fetch-collections-job.c
index dcbda47..e86d24a 100644
--- a/src/photos-fetch-collections-job.c
+++ b/src/photos-fetch-collections-job.c
@@ -254,7 +254,7 @@ photos_fetch_collections_job_run (PhotosFetchCollectionsJob *self,
 
   query = photos_query_builder_fetch_collections_query (state, self->urn);
   photos_tracker_queue_select (self->queue,
-                               query->sparql,
+                               query,
                                cancellable,
                                photos_fetch_collections_job_query_executed,
                                g_object_ref (task),
diff --git a/src/photos-fetch-ids-job.c b/src/photos-fetch-ids-job.c
index 0b92256..7512eb7 100644
--- a/src/photos-fetch-ids-job.c
+++ b/src/photos-fetch-ids-job.c
@@ -242,7 +242,7 @@ photos_fetch_ids_job_run (PhotosFetchIdsJob *self,
 
   query = photos_query_builder_global_query (state, PHOTOS_QUERY_FLAGS_SEARCH, NULL);
   photos_tracker_queue_select (self->queue,
-                               query->sparql,
+                               query,
                                cancellable,
                                photos_fetch_ids_job_query_executed,
                                g_object_ref (task),
diff --git a/src/photos-offset-controller.c b/src/photos-offset-controller.c
index 2c15cfd..226760b 100644
--- a/src/photos-offset-controller.c
+++ b/src/photos-offset-controller.c
@@ -281,7 +281,7 @@ photos_offset_controller_reset_count (PhotosOffsetController *self)
   g_return_if_fail (query != NULL);
 
   photos_tracker_queue_select (priv->queue,
-                               query->sparql,
+                               query,
                                NULL,
                                photos_offset_controller_reset_count_query_executed,
                                g_object_ref (self),
diff --git a/src/photos-properties-dialog.c b/src/photos-properties-dialog.c
index 22129b4..07af96e 100644
--- a/src/photos-properties-dialog.c
+++ b/src/photos-properties-dialog.c
@@ -523,7 +523,7 @@ photos_properties_dialog_constructed (GObject *object)
 
       query = photos_query_builder_location_query (state, location);
       photos_tracker_queue_select (self->queue,
-                                   query->sparql,
+                                   query,
                                    NULL,
                                    photos_properties_dialog_location_query_executed,
                                    g_object_ref (self),
diff --git a/src/photos-set-collection-job.c b/src/photos-set-collection-job.c
index 4f0af7c..36933b9 100644
--- a/src/photos-set-collection-job.c
+++ b/src/photos-set-collection-job.c
@@ -248,7 +248,7 @@ photos_set_collection_job_run (PhotosSetCollectionJob *self,
       self->running_jobs++;
       query = photos_query_builder_set_collection_query (state, urn, self->collection_urn, self->setting);
       photos_tracker_queue_update (self->queue,
-                                   query->sparql,
+                                   query,
                                    NULL,
                                    photos_set_collection_job_query_executed,
                                    g_object_ref (self),
diff --git a/src/photos-single-item-job.c b/src/photos-single-item-job.c
index d342528..bed9a85 100644
--- a/src/photos-single-item-job.c
+++ b/src/photos-single-item-job.c
@@ -223,7 +223,7 @@ photos_single_item_job_run (PhotosSingleItemJob *self,
 
   query = photos_query_builder_single_query (state, flags, self->urn);
   photos_tracker_queue_select (self->queue,
-                               query->sparql,
+                               query,
                                cancellable,
                                photos_single_item_job_query_executed,
                                g_object_ref (task),
diff --git a/src/photos-tracker-change-monitor.c b/src/photos-tracker-change-monitor.c
index 052ce47..92a84d4 100644
--- a/src/photos-tracker-change-monitor.c
+++ b/src/photos-tracker-change-monitor.c
@@ -32,6 +32,7 @@
 #include "photos-tracker-change-monitor.h"
 #include "photos-tracker-queue.h"
 #include "photos-tracker-resources.h"
+#include "photos-query.h"
 
 
 struct _PhotosTrackerChangeMonitor
@@ -258,6 +259,7 @@ photos_tracker_change_monitor_process_events (PhotosTrackerChangeMonitor *self)
   GQueue *events;
   GString *sparql;
   PhotosTrackerChangeMonitorQueryData *data;
+  PhotosQuery *query = NULL;
   gpointer id;
 
   events = self->pending_events;
@@ -276,15 +278,18 @@ photos_tracker_change_monitor_process_events (PhotosTrackerChangeMonitor *self)
 
   g_string_append (sparql, " {}");
 
+  query = photos_query_new (NULL, g_strdup (sparql->str));
+
   data = photos_tracker_change_monitor_query_data_new (self, id_table, events);
   photos_tracker_queue_select (self->queue,
-                               sparql->str,
+                               query,
                                NULL,
                                photos_tracker_change_monitor_query_executed,
                                data,
                                NULL);
 
   g_string_free (sparql, TRUE);
+  photos_query_free (query);
   return G_SOURCE_REMOVE;
 }
 
diff --git a/src/photos-tracker-controller.c b/src/photos-tracker-controller.c
index 5a47afc..79c82e7 100644
--- a/src/photos-tracker-controller.c
+++ b/src/photos-tracker-controller.c
@@ -295,7 +295,7 @@ photos_tracker_controller_perform_current_query (PhotosTrackerController *self)
     }
 
   photos_tracker_queue_select (priv->queue,
-                               priv->current_query->sparql,
+                               priv->current_query,
                                priv->cancellable,
                                photos_tracker_controller_query_executed,
                                g_object_ref (self),
diff --git a/src/photos-tracker-queue.c b/src/photos-tracker-queue.c
index dfbdd0b..4043f49 100644
--- a/src/photos-tracker-queue.c
+++ b/src/photos-tracker-queue.c
@@ -295,7 +295,7 @@ photos_tracker_queue_dup_singleton (GCancellable *cancellable, GError **error)
 
 void
 photos_tracker_queue_select (PhotosTrackerQueue *self,
-                             const gchar *sparql,
+                             PhotosQuery *query,
                              GCancellable *cancellable,
                              GAsyncReadyCallback callback,
                              gpointer user_data,
@@ -306,7 +306,7 @@ photos_tracker_queue_select (PhotosTrackerQueue *self,
   if (cancellable != NULL)
     g_object_ref (cancellable);
 
-  data = photos_tracker_queue_data_new (sparql,
+  data = photos_tracker_queue_data_new (query->sparql,
                                         PHOTOS_TRACKER_QUERY_SELECT,
                                         cancellable,
                                         callback,
@@ -320,7 +320,7 @@ photos_tracker_queue_select (PhotosTrackerQueue *self,
 
 void
 photos_tracker_queue_update (PhotosTrackerQueue *self,
-                             const gchar *sparql,
+                             PhotosQuery *query,
                              GCancellable *cancellable,
                              GAsyncReadyCallback callback,
                              gpointer user_data,
@@ -331,7 +331,7 @@ photos_tracker_queue_update (PhotosTrackerQueue *self,
   if (cancellable != NULL)
     g_object_ref (cancellable);
 
-  data = photos_tracker_queue_data_new (sparql,
+  data = photos_tracker_queue_data_new (query->sparql,
                                         PHOTOS_TRACKER_QUERY_UPDATE,
                                         cancellable,
                                         callback,
@@ -345,7 +345,7 @@ photos_tracker_queue_update (PhotosTrackerQueue *self,
 
 void
 photos_tracker_queue_update_blank (PhotosTrackerQueue *self,
-                                   const gchar *sparql,
+                                   PhotosQuery *query,
                                    GCancellable *cancellable,
                                    GAsyncReadyCallback callback,
                                    gpointer user_data,
@@ -356,7 +356,7 @@ photos_tracker_queue_update_blank (PhotosTrackerQueue *self,
   if (cancellable != NULL)
     g_object_ref (cancellable);
 
-  data = photos_tracker_queue_data_new (sparql,
+  data = photos_tracker_queue_data_new (query->sparql,
                                         PHOTOS_TRACKER_QUERY_UPDATE_BLANK,
                                         cancellable,
                                         callback,
diff --git a/src/photos-tracker-queue.h b/src/photos-tracker-queue.h
index 2152fa4..6a980d5 100644
--- a/src/photos-tracker-queue.h
+++ b/src/photos-tracker-queue.h
@@ -27,6 +27,8 @@
 
 #include <gio/gio.h>
 
+#include "photos-query.h"
+
 G_BEGIN_DECLS
 
 #define PHOTOS_TYPE_TRACKER_QUEUE (photos_tracker_queue_get_type ())
@@ -35,21 +37,21 @@ G_DECLARE_FINAL_TYPE (PhotosTrackerQueue, photos_tracker_queue, PHOTOS, TRACKER_
 PhotosTrackerQueue    *photos_tracker_queue_dup_singleton          (GCancellable *cancellable, GError 
**error);
 
 void                   photos_tracker_queue_select                 (PhotosTrackerQueue *self,
-                                                                    const gchar *sparql,
+                                                                    PhotosQuery *query,
                                                                     GCancellable *cancellable,
                                                                     GAsyncReadyCallback callback,
                                                                     gpointer user_data,
                                                                     GDestroyNotify destroy_data);
 
 void                   photos_tracker_queue_update                 (PhotosTrackerQueue *self,
-                                                                    const gchar *sparql,
+                                                                    PhotosQuery *query,
                                                                     GCancellable *cancellable,
                                                                     GAsyncReadyCallback callback,
                                                                     gpointer user_data,
                                                                     GDestroyNotify destroy_data);
 
 void                   photos_tracker_queue_update_blank           (PhotosTrackerQueue *self,
-                                                                    const gchar *sparql,
+                                                                    PhotosQuery *query,
                                                                     GCancellable *cancellable,
                                                                     GAsyncReadyCallback callback,
                                                                     gpointer user_data,
diff --git a/src/photos-update-mtime-job.c b/src/photos-update-mtime-job.c
index 6aa92da..93fa1d1 100644
--- a/src/photos-update-mtime-job.c
+++ b/src/photos-update-mtime-job.c
@@ -185,7 +185,7 @@ photos_update_mtime_job_run (PhotosUpdateMtimeJob *self,
 
   query = photos_query_builder_update_mtime_query (state, self->urn);
   photos_tracker_queue_update (self->queue,
-                               query->sparql,
+                               query,
                                cancellable,
                                photos_update_mtime_job_query_executed,
                                g_object_ref (task),
diff --git a/src/photos-utils.c b/src/photos-utils.c
index 0d8de9e..a6e2fe2 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -1315,10 +1315,13 @@ void
 photos_utils_set_edited_name (const gchar *urn, const gchar *title)
 {
   GError *error;
+  PhotosQuery *query = NULL;
   PhotosTrackerQueue *queue = NULL;
   gchar *sparql = NULL;
 
   sparql = g_strdup_printf ("INSERT OR REPLACE { <%s> nie:title \"%s\" }", urn, title);
+  query = photos_query_new (NULL, sparql);
+  sparql = NULL;
 
   error = NULL;
   queue = photos_tracker_queue_dup_singleton (NULL, &error);
@@ -1329,10 +1332,11 @@ photos_utils_set_edited_name (const gchar *urn, const gchar *title)
       goto out;
     }
 
-  photos_tracker_queue_update (queue, sparql, NULL, photos_utils_update_executed, g_strdup (urn), g_free);
+  photos_tracker_queue_update (queue, query, NULL, photos_utils_update_executed, g_strdup (urn), g_free);
 
  out:
   g_clear_object (&queue);
+  g_clear_pointer (&query, (GDestroyNotify) photos_query_free);
   g_free (sparql);
 }
 
@@ -1341,12 +1345,15 @@ void
 photos_utils_set_favorite (const gchar *urn, gboolean is_favorite)
 {
   GError *error;
+  PhotosQuery *query = NULL;
   PhotosTrackerQueue *queue = NULL;
   gchar *sparql = NULL;
 
   sparql = g_strdup_printf ("%s { <%s> nao:hasTag nao:predefined-tag-favorite }",
                             (is_favorite) ? "INSERT OR REPLACE" : "DELETE",
                             urn);
+  query = photos_query_new (NULL, sparql);
+  sparql = NULL;
 
   error = NULL;
   queue = photos_tracker_queue_dup_singleton (NULL, &error);
@@ -1357,11 +1364,12 @@ photos_utils_set_favorite (const gchar *urn, gboolean is_favorite)
       goto out;
     }
 
-  photos_tracker_queue_update (queue, sparql, NULL, photos_utils_update_executed, g_strdup (urn), g_free);
+  photos_tracker_queue_update (queue, query, NULL, photos_utils_update_executed, g_strdup (urn), g_free);
 
  out:
   g_free (sparql);
   g_clear_object (&queue);
+  g_clear_pointer (&query, (GDestroyNotify) photos_query_free);
 }
 
 


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