[tracker/wip/carlosg/notifier-service-queries: 10/12] libtracker-sparql: Perform notifier queries on the right service
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/notifier-service-queries: 10/12] libtracker-sparql: Perform notifier queries on the right service
- Date: Sun, 21 Jun 2020 21:31:44 +0000 (UTC)
commit 9d46bf7aae2c51463cf9e67751029ffed7fa0b53
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-direct/tracker-direct.c | 2 +-
src/libtracker-sparql/tracker-notifier-private.h | 1 -
src/libtracker-sparql/tracker-notifier.c | 89 +++++++++++++++++++-----
3 files changed, 74 insertions(+), 18 deletions(-)
---
diff --git a/src/libtracker-direct/tracker-direct.c b/src/libtracker-direct/tracker-direct.c
index ebae03d95..355c5debf 100644
--- a/src/libtracker-direct/tracker-direct.c
+++ b/src/libtracker-direct/tracker-direct.c
@@ -405,7 +405,7 @@ lookup_event_cache (TrackerNotifier *notifier,
cache = g_hash_table_lookup (events, GINT_TO_POINTER (graph_id));
if (!cache) {
- cache = _tracker_notifier_event_cache_new (notifier, NULL, graph);
+ cache = _tracker_notifier_event_cache_new (notifier, graph);
g_hash_table_insert (events, GINT_TO_POINTER (graph_id), cache);
}
diff --git a/src/libtracker-sparql/tracker-notifier-private.h
b/src/libtracker-sparql/tracker-notifier-private.h
index 9d019f6ca..aabe9f1bc 100644
--- a/src/libtracker-sparql/tracker-notifier-private.h
+++ b/src/libtracker-sparql/tracker-notifier-private.h
@@ -27,7 +27,6 @@
typedef struct _TrackerNotifierEventCache TrackerNotifierEventCache;
TrackerNotifierEventCache * _tracker_notifier_event_cache_new (TrackerNotifier *notifier,
- const gchar *service,
const gchar *graph);
void _tracker_notifier_event_cache_free (TrackerNotifierEventCache *event_cache);
diff --git a/src/libtracker-sparql/tracker-notifier.c b/src/libtracker-sparql/tracker-notifier.c
index 7601e1aea..1f529f584 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;
@@ -91,7 +92,7 @@ struct _TrackerNotifierPrivate {
};
struct _TrackerNotifierEventCache {
- gchar *service;
+ TrackerNotifierSubscription *subscription;
gchar *graph;
TrackerNotifier *notifier;
GSequence *sequence;
@@ -192,29 +193,35 @@ compare_event_cb (gconstpointer a,
return event1->id - event2->id;
}
-TrackerNotifierEventCache *
-_tracker_notifier_event_cache_new (TrackerNotifier *notifier,
- const gchar *service,
- const gchar *graph)
+static TrackerNotifierEventCache *
+_tracker_notifier_event_cache_new_full (TrackerNotifier *notifier,
+ TrackerNotifierSubscription *subscription,
+ const gchar *graph)
{
TrackerNotifierEventCache *event_cache;
event_cache = g_new0 (TrackerNotifierEventCache, 1);
event_cache->notifier = g_object_ref (notifier);
- event_cache->service = g_strdup (service);
+ event_cache->subscription = subscription;
event_cache->graph = g_strdup (graph);
event_cache->sequence = g_sequence_new ((GDestroyNotify) tracker_notifier_event_unref);
return event_cache;
}
+TrackerNotifierEventCache *
+_tracker_notifier_event_cache_new (TrackerNotifier *notifier,
+ const gchar *graph)
+{
+ return _tracker_notifier_event_cache_new_full (notifier, NULL, graph);
+}
+
void
_tracker_notifier_event_cache_free (TrackerNotifierEventCache *event_cache)
{
g_sequence_free (event_cache->sequence);
g_object_unref (event_cache->notifier);
g_free (event_cache->graph);
- g_free (event_cache->service);
g_free (event_cache);
}
@@ -309,16 +316,53 @@ compose_uri (const gchar *service,
return g_strdup_printf ("dbus:%s", service);
}
+static gchar *
+get_service_name (TrackerNotifier *notifier,
+ TrackerNotifierEventCache *cache)
+{
+ TrackerNotifierSubscription *subscription;
+ TrackerNotifierPrivate *priv;
+
+ priv = tracker_notifier_get_instance_private (notifier);
+ subscription = cache->subscription;
+
+ if (!subscription)
+ return NULL;
+
+ if (TRACKER_BUS_IS_CONNECTION (priv->connection)) {
+ gchar *bus_name, *bus_object_path;
+ gboolean is_self;
+
+ g_object_get (priv->connection,
+ "bus-name", &bus_name,
+ "bus-object-path", &bus_object_path,
+ NULL);
+
+ is_self = (g_strcmp0 (bus_name, subscription->service) == 0 &&
+ g_strcmp0 (bus_object_path, subscription->object_path) == 0);
+ g_free (bus_name);
+ g_free (bus_object_path);
+
+ if (is_self)
+ return NULL;
+ }
+
+ return compose_uri (subscription->service, subscription->object_path);
+}
+
static gboolean
tracker_notifier_emit_events (TrackerNotifierEventCache *cache)
{
GPtrArray *events;
+ 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);
+ g_free (service);
}
return G_SOURCE_REMOVE;
@@ -339,6 +383,7 @@ create_extra_info_query (TrackerNotifier *notifier,
{
GString *sparql, *filter;
gboolean has_elements = FALSE;
+ gchar *service;
GSequenceIter *iter;
filter = g_string_new (NULL);
@@ -362,13 +407,29 @@ create_extra_info_query (TrackerNotifier *notifier,
return NULL;
}
- sparql = g_string_new ("SELECT ?id tracker:uri(xsd:integer(?id)) ");
+ sparql = g_string_new ("SELECT ?id ?uri ");
+
+ service = get_service_name (notifier, cache);
+
+ if (service) {
+ g_string_append_printf (sparql,
+ "{ SERVICE <%s> ",
+ service);
+ }
g_string_append_printf (sparql,
- "{ VALUES ?id { %s } } "
- "ORDER BY ?id", filter->str);
+ "{ VALUES ?id { %s }"
+ " BIND (tracker:uri(?id) AS ?uri)"
+ "}", filter->str);
g_string_free (filter, TRUE);
+ if (service)
+ g_string_append (sparql, "} ");
+
+ g_string_append (sparql, "ORDER BY ?id");
+
+ g_free (service);
+
return g_string_free (sparql, FALSE);
}
@@ -474,14 +535,10 @@ graph_updated_cb (GDBusConnection *connection,
TrackerNotifierEventCache *cache;
GVariantIter *events;
const gchar *graph;
- gchar *service;
g_variant_get (parameters, "(sa{ii})", &graph, &events);
- service = compose_uri (subscription->service, subscription->object_path);
- cache = _tracker_notifier_event_cache_new (notifier, service, graph);
- g_free (service);
-
+ cache = _tracker_notifier_event_cache_new_full (notifier, subscription, graph);
handle_events (notifier, cache, events);
g_variant_iter_free (events);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]