[tracker/class-signal: 35/39] tracker-store, tracker-writeback: Changed the subject of Writeback signal to int



commit 91fd66d70446799e8818cbca1d9ab28f8b85f52a
Author: Philip Van Hoof <philip codeminded be>
Date:   Tue Aug 24 15:11:37 2010 +0200

    tracker-store, tracker-writeback: Changed the subject of Writeback signal to int
    
    This reduces D-Bus traffic for an internal API (the Writeback signal) and allows
    us to have to store less memory in tracker-store.

 data/dbus/tracker-resources.xml                    |    2 +-
 src/libtracker-client/tracker.c                    |    2 +-
 src/libtracker-common/tracker-dbus.h               |    4 +-
 src/miners/flickr/tracker-writeback.c              |    2 +-
 src/tracker-store/tracker-resources.c              |    2 +-
 src/tracker-store/tracker-writeback.c              |    6 +-
 src/tracker-writeback/tracker-main.c               |   13 ++---
 src/tracker-writeback/tracker-marshal.list         |    2 +-
 src/tracker-writeback/tracker-writeback-consumer.c |   49 ++++++++++++++-----
 src/tracker-writeback/tracker-writeback-consumer.h |    2 +-
 .../tracker-writeback-dispatcher.c                 |    8 ++--
 .../tracker-writeback-dispatcher.h                 |    2 +-
 12 files changed, 58 insertions(+), 36 deletions(-)
---
diff --git a/data/dbus/tracker-resources.xml b/data/dbus/tracker-resources.xml
index 8e15123..e709adc 100644
--- a/data/dbus/tracker-resources.xml
+++ b/data/dbus/tracker-resources.xml
@@ -51,7 +51,7 @@
     </method>
 
    <signal name="Writeback">
-      <arg type="a{sai}" name="subjects" />
+      <arg type="a{iai}" name="subjects" />
    </signal>
 
    <signal name="ClassSignal">
diff --git a/src/libtracker-client/tracker.c b/src/libtracker-client/tracker.c
index b70c52a..0836606 100644
--- a/src/libtracker-client/tracker.c
+++ b/src/libtracker-client/tracker.c
@@ -576,7 +576,7 @@ client_constructed (GObject *object)
 
 	dbus_g_proxy_add_signal (private->proxy_resources,
 	                         "Writeback",
-	                         TRACKER_TYPE_STR_ARRAY_MAP,
+	                         TRACKER_TYPE_INT_ARRAY_MAP,
 	                         G_TYPE_INVALID);
 
 	private->is_constructed = TRUE;
diff --git a/src/libtracker-common/tracker-dbus.h b/src/libtracker-common/tracker-dbus.h
index 15c88f0..483c4b7 100644
--- a/src/libtracker-common/tracker-dbus.h
+++ b/src/libtracker-common/tracker-dbus.h
@@ -38,8 +38,8 @@ G_BEGIN_DECLS
 #define TRACKER_DBUS_ERROR        tracker_dbus_error_quark()
 
 
-#define TRACKER_TYPE_STR_ARRAY_MAP	\
-	dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, DBUS_TYPE_G_INT_ARRAY)
+#define TRACKER_TYPE_INT_ARRAY_MAP	\
+	dbus_g_type_get_map ("GHashTable", G_TYPE_INT, DBUS_TYPE_G_INT_ARRAY)
 
 #define TRACKER_TYPE_THREE_INT_ARRAY	\
 	dbus_g_type_get_collection ("GPtrArray", \
diff --git a/src/miners/flickr/tracker-writeback.c b/src/miners/flickr/tracker-writeback.c
index c4943b0..2011cad 100644
--- a/src/miners/flickr/tracker-writeback.c
+++ b/src/miners/flickr/tracker-writeback.c
@@ -74,7 +74,7 @@ tracker_writeback_init (void)
 
 	dbus_g_proxy_add_signal (proxy_resources,
 	                         "Writeback",
-	                         TRACKER_TYPE_STR_ARRAY_MAP,
+	                         TRACKER_TYPE_INT_ARRAY_MAP,
 	                         G_TYPE_INVALID);
 }
 
diff --git a/src/tracker-store/tracker-resources.c b/src/tracker-store/tracker-resources.c
index a7ac25c..4ba91ee 100644
--- a/src/tracker-store/tracker-resources.c
+++ b/src/tracker-store/tracker-resources.c
@@ -119,7 +119,7 @@ tracker_resources_class_init (TrackerResourcesClass *klass)
 		              NULL, NULL,
 		              g_cclosure_marshal_VOID__BOXED,
 		              G_TYPE_NONE, 1,
-		              TRACKER_TYPE_STR_ARRAY_MAP);
+		              TRACKER_TYPE_INT_ARRAY_MAP);
 
 	/* This is just for introspection to work */
 	signals[CLASSSIGNAL] =
diff --git a/src/tracker-store/tracker-writeback.c b/src/tracker-store/tracker-writeback.c
index b519947..0e54226 100644
--- a/src/tracker-store/tracker-writeback.c
+++ b/src/tracker-store/tracker-writeback.c
@@ -78,13 +78,13 @@ tracker_writeback_check (gint         graph_id,
 
 	if (g_hash_table_lookup (private->allowances, GINT_TO_POINTER (pred_id))) {
 		if (!private->events) {
-			private->events = g_hash_table_new_full (g_str_hash, g_str_equal,
-			                                         (GDestroyNotify) g_free,
+			private->events = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+			                                         (GDestroyNotify) NULL,
 			                                         (GDestroyNotify) array_free);
 		}
 
 		g_hash_table_insert (private->events,
-		                     g_strdup (subject),
+		                     GINT_TO_POINTER (subject_id),
 		                     rdf_types_to_array (rdf_types));
 	}
 }
diff --git a/src/tracker-writeback/tracker-main.c b/src/tracker-writeback/tracker-main.c
index ec64570..66ab0f7 100644
--- a/src/tracker-writeback/tracker-main.c
+++ b/src/tracker-writeback/tracker-main.c
@@ -59,7 +59,7 @@ static GOptionEntry  entries[] = {
 };
 
 typedef struct {
-	gchar  *subject;
+	gint    subject;
 	GArray *rdf_types;
 } WritebackData;
 
@@ -68,14 +68,14 @@ static TrackerWritebackDispatcher *dispatcher = NULL;
 static GMainContext *dispatcher_context = NULL;
 
 static WritebackData *
-writeback_data_new (const gchar  *subject,
-                    GArray       *rdf_types)
+writeback_data_new (gint    subject,
+                    GArray *rdf_types)
 {
 	WritebackData *data;
 	guint i;
 
 	data = g_slice_new (WritebackData);
-	data->subject = g_strdup (subject);
+	data->subject = subject;
 
 	data->rdf_types = g_array_sized_new (FALSE, FALSE, sizeof (gint), rdf_types->len);
 
@@ -90,7 +90,6 @@ writeback_data_new (const gchar  *subject,
 static void
 writeback_data_free (WritebackData *data)
 {
-	g_free (data->subject);
 	g_array_free (data->rdf_types, TRUE);
 	g_slice_free (WritebackData, data);
 }
@@ -113,12 +112,12 @@ on_writeback_idle_cb (gpointer user_data)
 /* This callback run in the dispatcher thread */
 static void
 on_writeback_cb (TrackerWritebackDispatcher *dispatcher,
-                 const gchar                *subject,
+                 gint                        subject,
                  GArray                     *rdf_types)
 {
 	WritebackData *data;
 
-	g_message ("Got writeback petition on thread '%p' for subject '%s'",
+	g_message ("Got writeback petition on thread '%p' for subject '%d'",
 	           g_thread_self (), subject);
 
 	data = writeback_data_new (subject, rdf_types);
diff --git a/src/tracker-writeback/tracker-marshal.list b/src/tracker-writeback/tracker-marshal.list
index fbb2c47..e75f514 100644
--- a/src/tracker-writeback/tracker-marshal.list
+++ b/src/tracker-writeback/tracker-marshal.list
@@ -1,2 +1,2 @@
 VOID:BOXED
-VOID:STRING,BOXED
+VOID:INT,BOXED
diff --git a/src/tracker-writeback/tracker-writeback-consumer.c b/src/tracker-writeback/tracker-writeback-consumer.c
index 968361f..cd71348 100644
--- a/src/tracker-writeback/tracker-writeback-consumer.c
+++ b/src/tracker-writeback/tracker-writeback-consumer.c
@@ -37,7 +37,7 @@
 #define TRACKER_INTERFACE_RESOURCES "org.freedesktop.Tracker1.Resources"
 
 typedef struct {
-	gchar  *subject;
+	gint    subject;
 	GStrv   rdf_types;
 	GArray *rdf_types_int;
 } QueryData;
@@ -214,7 +214,7 @@ sparql_query_cb (GObject      *object,
 				if (sparql_rdf_types_match (module_types, (const gchar * const *) rdf_types)) {
 					TrackerWriteback *writeback;
 
-					g_message ("  Updating metadata for subject:'%s' using module:'%s'",
+					g_message ("  Updating metadata for subject:'%d' using module:'%s'",
 					           data->subject,
 					           module->name);
 
@@ -234,7 +234,6 @@ sparql_query_cb (GObject      *object,
 		g_error_free (error);
 	}
 
-	g_free (data->subject);
 	g_strfreev (data->rdf_types);
 	g_slice_free (QueryData, data);
 
@@ -251,16 +250,19 @@ rdf_types_to_uris_cb (GObject      *object,
 	QueryData *data;
 	GError *error = NULL;
 	TrackerSparqlCursor *cursor;
+	TrackerSparqlConnection *connection;
 
 	consumer = TRACKER_WRITEBACK_CONSUMER (user_data);
 	priv = TRACKER_WRITEBACK_CONSUMER_GET_PRIVATE (consumer);
+	connection = TRACKER_SPARQL_CONNECTION (object);
 
 	data = g_queue_peek_head (priv->process_queue);
 
-	cursor = tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION (object), result, &error);
+	cursor = tracker_sparql_connection_query_finish (connection, result, &error);
 
 	if (!error) {
 		gchar *query;
+		const gchar *subject;
 		GArray *rdf_types;
 		guint i;
 
@@ -279,12 +281,26 @@ rdf_types_to_uris_cb (GObject      *object,
 
 		g_object_unref (cursor);
 
+		query = g_strdup_printf ("SELECT tracker:subject (%d) {}", data->subject);
+		cursor = tracker_sparql_connection_query (connection, query, NULL, NULL);
+		g_free (query);
+
+		if (cursor && tracker_sparql_cursor_next (cursor, NULL, NULL)) {
+			subject = tracker_sparql_cursor_get_string (cursor, 0, NULL);
+			if (!subject)
+				goto trouble;
+		} else {
+			if (cursor)
+				g_object_unref (cursor);
+			goto trouble;
+		}
+
 		query = g_strdup_printf ("SELECT ?url '%s' ?predicate ?object {"
 		                         "  <%s> ?predicate ?object ; "
 		                         "       nie:url ?url ."
 		                         "  ?predicate tracker:writeback true "
 		                         "}",
-		                         data->subject, data->subject);
+		                         subject, subject);
 
 		tracker_sparql_connection_query_async (priv->connection,
 		                                       query,
@@ -295,17 +311,25 @@ rdf_types_to_uris_cb (GObject      *object,
 		g_free (query);
 
 	} else {
-		g_message ("  No files qualify for updates (%s)", error->message);
-		g_error_free (error);
+		goto trouble;
+	}
+
+	g_array_free (data->rdf_types_int, TRUE);
+
+	return;
+
+trouble:
+		if (error) {
+			g_message ("  No files qualify for updates (%s)", error->message);
+			g_error_free (error);
+		}
+		g_array_free (data->rdf_types_int, TRUE);
 		data = g_queue_pop_head (priv->process_queue);
-		g_free (data->subject);
 		g_strfreev (data->rdf_types);
 		g_slice_free (QueryData, data);
 
 		priv->idle_id = g_idle_add (process_queue_cb, consumer);
-	}
 
-	g_array_free (data->rdf_types_int, TRUE);
 }
 
 static gboolean
@@ -357,7 +381,7 @@ process_queue_cb (gpointer user_data)
 
 void
 tracker_writeback_consumer_add_subject (TrackerWritebackConsumer *consumer,
-                                        const gchar              *subject,
+                                        gint                      subject,
                                         GArray                   *rdf_types)
 {
 	TrackerWritebackConsumerPrivate *priv;
@@ -365,13 +389,12 @@ tracker_writeback_consumer_add_subject (TrackerWritebackConsumer *consumer,
 	guint i;
 
 	g_return_if_fail (TRACKER_IS_WRITEBACK_CONSUMER (consumer));
-	g_return_if_fail (subject != NULL);
 	g_return_if_fail (rdf_types != NULL);
 
 	priv = TRACKER_WRITEBACK_CONSUMER_GET_PRIVATE (consumer);
 
 	data = g_slice_new (QueryData);
-	data->subject = g_strdup (subject);
+	data->subject = subject;
 
 	data->rdf_types_int = g_array_sized_new (FALSE, FALSE, sizeof (gint), rdf_types->len);
 
diff --git a/src/tracker-writeback/tracker-writeback-consumer.h b/src/tracker-writeback/tracker-writeback-consumer.h
index 6e20054..bb875a1 100644
--- a/src/tracker-writeback/tracker-writeback-consumer.h
+++ b/src/tracker-writeback/tracker-writeback-consumer.h
@@ -49,7 +49,7 @@ GType                      tracker_writeback_consumer_get_type (void) G_GNUC_CON
 TrackerWritebackConsumer * tracker_writeback_consumer_new      (void);
 
 void tracker_writeback_consumer_add_subject (TrackerWritebackConsumer *consumer,
-                                             const gchar              *subject,
+                                             gint                      subject,
                                              GArray                   *rdf_types);
 
 G_END_DECLS
diff --git a/src/tracker-writeback/tracker-writeback-dispatcher.c b/src/tracker-writeback/tracker-writeback-dispatcher.c
index 0cb816c..ac3d329 100644
--- a/src/tracker-writeback/tracker-writeback-dispatcher.c
+++ b/src/tracker-writeback/tracker-writeback-dispatcher.c
@@ -91,8 +91,8 @@ tracker_writeback_dispatcher_class_init (TrackerWritebackDispatcherClass *klass)
 		              G_SIGNAL_RUN_LAST,
 		              G_STRUCT_OFFSET (TrackerWritebackDispatcherClass, writeback),
 		              NULL, NULL,
-		              tracker_marshal_VOID__STRING_BOXED,
-		              G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_ARRAY);
+		              tracker_marshal_VOID__INT_BOXED,
+		              G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_ARRAY);
 
 	g_type_class_add_private (object_class, sizeof (TrackerWritebackDispatcherPrivate));
 }
@@ -114,7 +114,7 @@ handle_writeback_signal (TrackerWritebackDispatcher *dispatcher,
 
 	signature = dbus_message_iter_get_signature (&iter);
 
-	if (g_strcmp0 (signature, "a{sai}") != 0) {
+	if (g_strcmp0 (signature, "a{iai}") != 0) {
 		g_critical ("  Unexpected message signature '%s'", signature);
 		g_free (signature);
 		return;
@@ -129,7 +129,7 @@ handle_writeback_signal (TrackerWritebackDispatcher *dispatcher,
 
 		while ((arg_type = dbus_message_iter_get_arg_type (&arr)) != DBUS_TYPE_INVALID) {
 			DBusMessageIter dict, types_arr;
-			const gchar *subject;
+			gint subject;
 			GArray *rdf_types;
 
 			rdf_types = g_array_new (FALSE, FALSE, sizeof (gint));
diff --git a/src/tracker-writeback/tracker-writeback-dispatcher.h b/src/tracker-writeback/tracker-writeback-dispatcher.h
index 03e3684..f98a948 100644
--- a/src/tracker-writeback/tracker-writeback-dispatcher.h
+++ b/src/tracker-writeback/tracker-writeback-dispatcher.h
@@ -44,7 +44,7 @@ struct TrackerWritebackDispatcherClass {
 	GObjectClass parent_class;
 
 	void (* writeback) (TrackerWritebackDispatcher *dispatcher,
-	                    const gchar                *subject,
+	                    gint                        subject,
 	                    GArray                     *rdf_types);
 };
 



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