[tracker/pushplugin] Various bugfixes, made register_client async



commit 0ad51106e4773edf623b2477d6b50548c0a4d633
Author: Philip Van Hoof <philip codeminded be>
Date:   Wed Sep 23 15:03:54 2009 +0200

    Various bugfixes, made register_client async

 src/plugins/evolution/tracker-evolution-plugin.c |  125 ++++++++++++++--------
 1 files changed, 78 insertions(+), 47 deletions(-)
---
diff --git a/src/plugins/evolution/tracker-evolution-plugin.c b/src/plugins/evolution/tracker-evolution-plugin.c
index 4cfe129..2f6c822 100644
--- a/src/plugins/evolution/tracker-evolution-plugin.c
+++ b/src/plugins/evolution/tracker-evolution-plugin.c
@@ -120,6 +120,7 @@ G_DEFINE_TYPE (TrackerEvolutionPlugin, tracker_evolution_plugin, TRACKER_TYPE_MI
  * during registration of accounts and folders). I know this is cruel. I know. */
 
 typedef struct {
+	TrackerEvolutionPlugin *self; /* weak */
 	guint64 last_checkout;
 } ClientRegistry;
 
@@ -171,6 +172,7 @@ typedef struct {
 
 typedef struct {
 	TrackerSparqlBuilder *sparql;
+	guint count;
 } QueuedSet;
 
 typedef struct {
@@ -881,6 +883,8 @@ many_idle_handler (gpointer user_data)
 
 	if (!queued_set) {
 		send_sparql_commit (user_data, TRUE);
+		g_object_set (user_data, "progress", 
+		              1.0, NULL);
 	}
 
 	return queued_set ? TRUE : FALSE;
@@ -897,8 +901,6 @@ many_idle_destroy (gpointer user_data)
 static void
 start_many_handler (TrackerEvolutionPlugin *self)
 {
-	/* We just slow it down to 'once per second' (for now, we can tweak this
-	 * afterward, of course, but once per second seems to work great) */
 	 g_idle_add_full (G_PRIORITY_LOW,
 	                  many_idle_handler,
 	                  g_object_ref (self),
@@ -1105,7 +1107,6 @@ introduce_walk_folders_in_folder (TrackerEvolutionPlugin *self,
 				QueuedSet *queued_set;
 				gboolean start_handler = FALSE;
 
-
 				/* The many_queue stuff:
 				 * Why is this? Ah! Good question and glad you ask.
 				 * We noticed that hammering the DBus isn't exactly
@@ -1116,18 +1117,26 @@ introduce_walk_folders_in_folder (TrackerEvolutionPlugin *self,
 				queued_set = g_slice_new (QueuedSet);
 
 				queued_set->sparql = sparql; /* Keep ref */
+				queued_set->count = count;
+
 				sparql = NULL;
 
 				if (!many_queue) {
 					many_queue = g_queue_new ();
-					priv->of_total = 0;
 					start_handler = TRUE;
 				}
 
 				g_queue_push_tail (many_queue, 
 				                   queued_set);
+
 				priv->of_total++;
 
+				if (priv->of_total > priv->total_popped) {
+					g_object_set (self, "progress", 
+					              (gdouble) (priv->of_total - priv->total_popped) / priv->of_total,
+					              NULL);
+				}
+
 				if (start_handler) {
 					start_many_handler (self);
 				}
@@ -1251,7 +1260,7 @@ introduce_store_deal_with_deleted (TrackerEvolutionPlugin *self,
 
 	}
 
-	send_sparql_commit (self, TRUE);
+	send_sparql_commit (self, FALSE);
 
 	sqlite3_finalize (stmt);
 	sqlite3_free (query);
@@ -1688,74 +1697,95 @@ introduce_accounts_to (TrackerEvolutionPlugin *self,
 }
 
 static void
+register_client_second_half (ClientRegistry *info)
+{
+	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (info->self);
+	guint64 too_old = get_last_deleted_time (info->self);
+
+	/* If registrar's modseq is too old, send Cleanup (). This means that
+	 * we tell it to start over (it must invalidate what it has). */
+
+	if (info->last_checkout < too_old) {
+
+		send_sparql_update (info->self, "DELETE { ?s a rdfs:Resource } "
+		                                "WHERE { ?s nie:dataSource <" DATASOURCE_URN "> }");
+		send_sparql_commit (info->self, FALSE);
+
+		info->last_checkout = 0;
+	}
+
+	priv->last_time = info->last_checkout;
+
+	introduce_accounts_to (info->self, info);
+
+	priv->registered_clients = 
+		g_list_prepend (priv->registered_clients, info);
+}
+
+static void
+on_register_client_qry (GPtrArray *results, 
+                        GError    *error, 
+                        gpointer   user_data)
+{
+	ClientRegistry *info = user_data;
+	guint i;
+
+	if (error) {
+		g_warning ("%s\n", error->message);
+		g_error_free (error);
+		g_slice_free (ClientRegistry, info);
+		return;
+	}
+
+	if (!results) {
+		info->last_checkout = 0;
+	} else {
+		for (i = 0; i < results->len; i++) {
+			const gchar **str = g_ptr_array_index (results, i);
+			info->last_checkout = (guint64) tracker_string_to_date (str[0]);
+			break;
+		}
+		g_ptr_array_foreach (results, (GFunc) g_strfreev, NULL);
+		g_ptr_array_free (results, TRUE);
+	}
+
+	register_client_second_half (info);
+}
+
+static void
 register_client (TrackerEvolutionPlugin *self)
 {
 	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (self);
-	guint64 too_old = get_last_deleted_time (self);
 	ClientRegistry *info = g_slice_new0 (ClientRegistry);
-	GError *error = NULL;
+
+	info->self = self; /* weak */
 
 	if (!priv->client) {
 		return;
 	}
 
 	priv->total_popped = 0;
+	priv->of_total = 0;
 
 	if (!priv->resuming) {
-		GPtrArray *results;
 		const gchar *query;
-		guint i;
 
 		query = "SELECT ?c "
 			"WHERE { <" DATASOURCE_URN "> nie:contentLastModified ?c }";
 
-		results = tracker_resources_sparql_query (priv->client, query, &error);
+		tracker_resources_sparql_query_async (priv->client, query, 
+		                                      on_register_client_qry,
+		                                      info);
 
-		if (error) {
-			g_warning ("%s\n", error->message);
-			g_error_free (error);
-			return;
-		}
-
-		if (!results) {
-			info->last_checkout = 0;
-		} else {
-
-			for (i = 0; i < results->len; i++) {
-				const gchar **str = g_ptr_array_index (results, i);
-				info->last_checkout = (guint64) tracker_string_to_date (str[0]);
-				break;
-			}
-		}
-
-		g_ptr_array_foreach (results, (GFunc) g_strfreev, NULL);
-		g_ptr_array_free (results, TRUE);
 	} else {
 		/* This happens in case of resume, for example (which is just a 
 		 * complete restart. So we just get the same E-mails that we had
 		 * already) */
 
 		info->last_checkout = priv->last_time;
+		register_client_second_half (info);
 	}
 
-	/* If registrar's modseq is too old, send Cleanup (). This means that
-	 * we tell it to start over (it must invalidate what it has). */
-
-	if (info->last_checkout < too_old) {
-
-		send_sparql_update (self, "DELETE { ?s a rdfs:Resource } "
-		                          "WHERE { ?s nie:dataSource <" DATASOURCE_URN "> }");
-		send_sparql_commit (self, FALSE);
-
-		info->last_checkout = 0;
-	}
-
-	priv->last_time = info->last_checkout;
-
-	introduce_accounts_to (self, info);
-
-	priv->registered_clients = 
-		g_list_prepend (priv->registered_clients, info);
 
 }
 
@@ -2327,6 +2357,7 @@ miner_resumed (TrackerMiner *miner)
 	priv->resuming = TRUE;
 	priv->paused = FALSE;
 	priv->total_popped = 0;
+	priv->of_total = 0;
 
 	if (!priv->client) {
 		priv->client = tracker_connect (FALSE, G_MAXINT);



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