[tracker/wip/carlosg/notifier-service-queries: 3/3] libtracker-sparql: Perform notifier queries on the right service



commit 84d8ea1033f23e079987ad162d0128a0e9f63ac1
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Jun 21 14:45:19 2020 +0200

    libtracker-sparql: Perform notifier queries on the right service
    
    We must figure out (and shortcut) the cases where the service matches
    our own connection one (In the case of a bus TrackerSparqlConnection).
    In any other case, perform the queries on the same service that issued
    the GraphUpdated signal.
    
    Also ensure we set a coherent "service" argument in the ::events signal
    for those same connections.
    
    Fixes: https://gitlab.gnome.org/GNOME/tracker/-/issues/227

 src/libtracker-sparql/tracker-notifier.c | 47 +++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)
---
diff --git a/src/libtracker-sparql/tracker-notifier.c b/src/libtracker-sparql/tracker-notifier.c
index 7601e1aea..a0efdd4b7 100644
--- a/src/libtracker-sparql/tracker-notifier.c
+++ b/src/libtracker-sparql/tracker-notifier.c
@@ -71,6 +71,7 @@
 #include "tracker-private.h"
 #include "tracker-sparql-enum-types.h"
 #include <libtracker-common/tracker-common.h>
+#include <libtracker-bus/tracker-bus.h>
 
 typedef struct _TrackerNotifierPrivate TrackerNotifierPrivate;
 typedef struct _TrackerNotifierSubscription TrackerNotifierSubscription;
@@ -309,15 +310,47 @@ compose_uri (const gchar *service,
                return g_strdup_printf ("dbus:%s", service);
 }
 
+static const gchar *
+get_service_name (TrackerNotifier           *notifier,
+                  TrackerNotifierEventCache *cache)
+{
+       TrackerNotifierPrivate *priv;
+
+       priv = tracker_notifier_get_instance_private (notifier);
+
+       if (TRACKER_BUS_IS_CONNECTION (priv->connection)) {
+               gchar *bus_name, *bus_object_path, *uri;
+               gboolean is_self;
+
+               g_object_get (priv->connection,
+                             "bus-name", &bus_name,
+                             "bus-object-name", &bus_object_path,
+                             NULL);
+
+               uri = compose_uri (bus_name, bus_object_path);
+
+               is_self = g_strcmp0 (uri, cache->service) == 0;
+               g_free (bus_name);
+               g_free (bus_object_path);
+               g_free (uri);
+
+               return is_self ? NULL : cache->service;
+       }
+
+       return cache->service;
+}
+
 static gboolean
 tracker_notifier_emit_events (TrackerNotifierEventCache *cache)
 {
        GPtrArray *events;
+       const gchar *service;
 
        events = tracker_notifier_event_cache_take_events (cache);
 
        if (events) {
-               g_signal_emit (cache->notifier, signals[EVENTS], 0, cache->service, cache->graph, events);
+               service = get_service_name (cache->notifier, cache);
+               g_signal_emit (cache->notifier, signals[EVENTS], 0, service, cache->graph, events);
                g_ptr_array_unref (events);
        }
 
@@ -339,6 +372,7 @@ create_extra_info_query (TrackerNotifier           *notifier,
 {
        GString *sparql, *filter;
        gboolean has_elements = FALSE;
+       const gchar *service;
        GSequenceIter *iter;
 
        filter = g_string_new (NULL);
@@ -364,11 +398,22 @@ create_extra_info_query (TrackerNotifier           *notifier,
 
        sparql = g_string_new ("SELECT ?id tracker:uri(xsd:integer(?id)) ");
 
+       service = get_service_name (notifier, cache);
+
+       if (service) {
+               g_string_append_printf (sparql,
+                                       "{ SERVICE <%s> { SELECT ?id ",
+                                       service);
+       }
+
        g_string_append_printf (sparql,
                                "{ VALUES ?id { %s } } "
                                "ORDER BY ?id", filter->str);
        g_string_free (filter, TRUE);
 
+       if (service)
+               g_string_append_printf (sparql, "} } ");
+
        return g_string_free (sparql, FALSE);
 }
 


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