[tracker/dbus-fd-experiment: 5/19] Port libtracker-miner and FS miner to steroids



commit 845d56f7134dfe2895f1ab83108641718a600df5
Author: Adrien Bustany <abustany gnome org>
Date:   Thu Jun 3 20:58:45 2010 -0400

    Port libtracker-miner and FS miner to steroids

 src/libtracker-miner/tracker-miner-fs.c     |   52 ++++++++++++--------------
 src/libtracker-miner/tracker-miner-object.c |   34 +++++++++---------
 src/libtracker-miner/tracker-miner-object.h |    3 +-
 src/miners/fs/tracker-miner-files-reindex.c |   32 ++++++++---------
 src/miners/fs/tracker-miner-files.c         |   20 +++++-----
 5 files changed, 68 insertions(+), 73 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 88403a6..22488ea 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -1042,12 +1042,12 @@ sparql_query_cb (GObject      *object,
                  gpointer      user_data)
 {
 	SparqlQueryData *data = user_data;
-	const GPtrArray *query_results;
+	TrackerResultIterator *iterator;
 	TrackerMiner *miner;
 	GError *error = NULL;
 
 	miner = TRACKER_MINER (object);
-	query_results = tracker_miner_execute_sparql_finish (miner, result, &error);
+	iterator = tracker_miner_execute_sparql_finish (miner, result, &error);
 
 	g_main_loop_quit (data->main_loop);
 
@@ -1057,19 +1057,18 @@ sparql_query_cb (GObject      *object,
 		return;
 	}
 
-	if (!query_results ||
-	    query_results->len == 0)
+	if (!iterator ||
+	    !tracker_result_iterator_has_next (iterator))
 		return;
 
-	if (query_results->len == 1) {
-		gchar **val;
+	tracker_result_iterator_next (iterator);
 
-		val = g_ptr_array_index (query_results, 0);
-		data->iri = g_strdup (val[0]);
+	if (!tracker_result_iterator_has_next (iterator)) {
+		data->iri = g_strdup (tracker_result_iterator_value (iterator, 0));
 		if (data->get_mime)
-			data->mime = g_strdup (val[1]);
+			data->mime = g_strdup (tracker_result_iterator_value (iterator, 1));
 	} else {
-		g_critical ("More than one URNs (%d) have been found for uri \"%s\"", query_results->len, data->uri);
+		g_critical ("More than one URNs have been found for uri \"%s\"", data->uri);
 	}
 }
 
@@ -1130,15 +1129,14 @@ cache_query_cb (GObject	     *object,
 		GAsyncResult *result,
 		gpointer      user_data)
 {
-	const GPtrArray *query_results;
+	TrackerResultIterator *iterator;
 	TrackerMiner *miner;
 	CacheQueryData *data;
 	GError *error = NULL;
-	guint i;
 
 	data = user_data;
 	miner = TRACKER_MINER (object);
-	query_results = tracker_miner_execute_sparql_finish (miner, result, &error);
+	iterator = tracker_miner_execute_sparql_finish (miner, result, &error);
 
 	g_main_loop_quit (data->main_loop);
 
@@ -1148,14 +1146,15 @@ cache_query_cb (GObject	     *object,
 		return;
 	}
 
-	for (i = 0; i < query_results->len; i++) {
+	while (tracker_result_iterator_has_next (iterator)) {
 		GFile *file;
-		GStrv strv;
 
-		strv = g_ptr_array_index (query_results, i);
-		file = g_file_new_for_uri (strv[0]);
+		tracker_result_iterator_next (iterator);
+		file = g_file_new_for_uri (tracker_result_iterator_value (iterator, 0));
 
-		g_hash_table_insert (data->values, file, g_strdup (strv[1]));
+		g_hash_table_insert (data->values,
+		                     file,
+		                     g_strdup (tracker_result_iterator_value (iterator, 1)));
 	}
 }
 
@@ -1616,23 +1615,20 @@ item_update_children_uri_cb (GObject      *object,
 	RecursiveMoveData *data = user_data;
 	GError *error = NULL;
 
-	const GPtrArray *query_results = tracker_miner_execute_sparql_finish (TRACKER_MINER (object), result, &error);
+	TrackerResultIterator *iterator = tracker_miner_execute_sparql_finish (TRACKER_MINER (object), result, &error);
 
 	if (error) {
 		g_critical ("Could not query children: %s", error->message);
 		g_error_free (error);
-	} else if (query_results) {
-		gint i;
-
-		for (i = 0; i < query_results->len; i++) {
+	} else if (iterator) {
+		while (tracker_result_iterator_has_next (iterator)) {
 			const gchar *child_source_uri, *child_mime, *child_urn;
 			gchar *child_uri;
-			GStrv row;
 
-			row = g_ptr_array_index (query_results, i);
-			child_urn = row[0];
-			child_source_uri = row[1];
-			child_mime = row[2];
+			tracker_result_iterator_next (iterator);
+			child_urn = tracker_result_iterator_value (iterator, 0);
+			child_source_uri = tracker_result_iterator_value (iterator, 1);
+			child_mime = tracker_result_iterator_value (iterator, 2);
 
 			if (!g_str_has_prefix (child_source_uri, data->source_uri)) {
 				g_warning ("Child URI '%s' does not start with parent URI '%s'",
diff --git a/src/libtracker-miner/tracker-miner-object.c b/src/libtracker-miner/tracker-miner-object.c
index 33827b8..275f69b 100644
--- a/src/libtracker-miner/tracker-miner-object.c
+++ b/src/libtracker-miner/tracker-miner-object.c
@@ -577,9 +577,9 @@ async_call_data_update_callback (AsyncCallData *data,
 }
 
 static void
-async_call_data_query_callback (AsyncCallData   *data,
-                                const GPtrArray *query_results,
-                                GError          *error)
+async_call_data_query_callback (AsyncCallData         *data,
+                                TrackerResultIterator *iterator,
+                                GError                *error)
 {
 	GAsyncReadyCallback callback;
 	GSimpleAsyncResult *result;
@@ -598,7 +598,7 @@ async_call_data_query_callback (AsyncCallData   *data,
 		                                    data->source_function);
 	}
 
-	g_simple_async_result_set_op_res_gpointer (result, (gpointer) query_results, NULL);
+	g_simple_async_result_set_op_res_gpointer (result, (gpointer) iterator, NULL);
 	g_simple_async_result_complete (result);
 	g_object_unref (result);
 }
@@ -648,19 +648,19 @@ sparql_update_cb (GError   *error,
 }
 
 static void
-sparql_query_cb (GPtrArray *result,
+sparql_query_cb (TrackerResultIterator *iterator,
                  GError    *error,
                  gpointer   user_data)
 {
 	AsyncCallData *data = user_data;
 
-	async_call_data_query_callback (data, result, error);
+	async_call_data_query_callback (data, iterator, error);
 
 	if (error) {
 		g_error_free (error);
 	} else {
-		if (result) {
-			tracker_dbus_results_ptr_array_free (&result);
+		if (iterator) {
+			tracker_result_iterator_free (iterator);
 		}
 	}
 
@@ -791,10 +791,10 @@ tracker_miner_execute_update (TrackerMiner        *miner,
 	                            user_data,
 	                            tracker_miner_execute_sparql);
 
-	data->id = tracker_resources_sparql_update_async (miner->private->client,
-	                                                  sparql,
-	                                                  sparql_update_cb,
-	                                                  data);
+	data->id = tracker_resources_sparql_update_fast_async (miner->private->client,
+	                                                       sparql,
+	                                                       sparql_update_cb,
+	                                                       data);
 }
 
 /**
@@ -852,9 +852,9 @@ tracker_miner_execute_sparql (TrackerMiner        *miner,
 
 	data = async_call_data_new (miner, cancellable, callback, user_data, tracker_miner_execute_sparql);
 
-	data->id = tracker_resources_sparql_query_async (miner->private->client,
-	                                                 sparql, sparql_query_cb,
-	                                                 data);
+	data->id = tracker_resources_sparql_query_iterate_async (miner->private->client,
+	                                                         sparql, sparql_query_cb,
+	                                                         data);
 }
 
 /**
@@ -868,7 +868,7 @@ tracker_miner_execute_sparql (TrackerMiner        *miner,
  *
  * Returns: a #GPtrArray with the sparql results which should not be freed.
  **/
-const GPtrArray *
+TrackerResultIterator*
 tracker_miner_execute_sparql_finish (TrackerMiner  *miner,
                                      GAsyncResult  *result,
                                      GError       **error)
@@ -879,7 +879,7 @@ tracker_miner_execute_sparql_finish (TrackerMiner  *miner,
 		return NULL;
 	}
 
-	return (const GPtrArray*) g_simple_async_result_get_op_res_gpointer (r);
+	return (TrackerResultIterator*) g_simple_async_result_get_op_res_gpointer (r);
 }
 
 /**
diff --git a/src/libtracker-miner/tracker-miner-object.h b/src/libtracker-miner/tracker-miner-object.h
index 8df514b..16044cc 100644
--- a/src/libtracker-miner/tracker-miner-object.h
+++ b/src/libtracker-miner/tracker-miner-object.h
@@ -114,7 +114,8 @@ void             tracker_miner_execute_sparql              (TrackerMiner
                                                             GCancellable         *cancellable,
                                                             GAsyncReadyCallback   callback,
                                                             gpointer              user_data);
-const GPtrArray* tracker_miner_execute_sparql_finish       (TrackerMiner         *miner,
+TrackerResultIterator*
+                 tracker_miner_execute_sparql_finish       (TrackerMiner         *miner,
                                                             GAsyncResult         *result,
                                                             GError              **error);
 void             tracker_miner_execute_batch_update        (TrackerMiner         *miner,
diff --git a/src/miners/fs/tracker-miner-files-reindex.c b/src/miners/fs/tracker-miner-files-reindex.c
index 0b418f8..70e4346 100644
--- a/src/miners/fs/tracker-miner-files-reindex.c
+++ b/src/miners/fs/tracker-miner-files-reindex.c
@@ -164,23 +164,21 @@ mime_types_data_destroy (gpointer data)
 }
 
 static void
-mime_types_cb (GPtrArray *result,
-               GError    *error,
-               gpointer   user_data)
+mime_types_cb (TrackerResultIterator *iterator,
+               GError                *error,
+               gpointer               user_data)
 {
 	MimeTypesData *mtd = user_data;
-	guint i;
 
 	if (!error) {
 		tracker_dbus_request_comment (mtd->request_id, mtd->context,
-		                              "Found %d files that will need reindexing",
-		                              result ? result->len : 0);
+		                              "Found files that will need reindexing");
 
-		for (i = 0; i < result->len; i++) {
-			GStrv *row = g_ptr_array_index (result, i);
+		while (tracker_result_iterator_has_next (iterator)) {
+			tracker_result_iterator_next (iterator);
 
-			if (row && row[0]) {
-				const gchar *url = (const gchar *) row[0];
+			if (tracker_result_iterator_value (iterator, 0)) {
+				const gchar *url = (const gchar *) tracker_result_iterator_value (iterator, 0);
 				GFile *file = g_file_new_for_uri (url);
 				tracker_miner_fs_file_add (TRACKER_MINER_FS (mtd->miner_files), file);
 				g_object_unref (file);
@@ -265,13 +263,13 @@ tracker_miner_files_reindex_mime_types (TrackerMinerFilesReindex  *object,
 	priv = TRACKER_MINER_FILES_REINDEX_GET_PRIVATE (object);
 
 	/* FIXME: save last call id */
-	tracker_resources_sparql_query_async (client, 
-	                                      query->str, 
-	                                      mime_types_cb, 
-	                                      mime_types_data_new (request_id, 
-	                                                           context, 
-	                                                           client,
-	                                                           priv->files_miner));
+	tracker_resources_sparql_query_iterate_async (client,
+	                                              query->str,
+	                                              mime_types_cb,
+	                                              mime_types_data_new (request_id,
+	                                                                   context,
+	                                                                   client,
+	                                                                   priv->files_miner));
 
 	g_string_free (query, TRUE);
 	g_object_unref (client);
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index 0fdca5f..e984387 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -690,14 +690,13 @@ query_mount_points_cb (GObject      *source,
 	GHashTableIter iter;
 	gpointer key, value;
 	GString *accumulator;
-	gint i;
 	GError *error = NULL;
-	const GPtrArray *query_results;
+	TrackerResultIterator *iterator;
 	GSList *uuids, *u;
 
-	query_results = tracker_miner_execute_sparql_finish (miner,
-	                                                     result,
-	                                                     &error);
+	iterator = tracker_miner_execute_sparql_finish (miner,
+	                                                result,
+	                                                &error);
 	if (error) {
 		g_critical ("Could not obtain the mounted volumes: %s", error->message);
 		g_error_free (error);
@@ -710,19 +709,20 @@ query_mount_points_cb (GObject      *source,
 	                                 (GDestroyNotify) g_free,
 	                                 NULL);
 
-	for (i = 0; i < query_results->len; i++) {
-		gchar **row;
+	while (tracker_result_iterator_has_next (iterator)) {
 		gint state;
+		const gchar *urn;
 
-		row = g_ptr_array_index (query_results, i);
 		state = VOLUME_MOUNTED_IN_STORE;
 
-		if (strcmp (row[0], TRACKER_NON_REMOVABLE_MEDIA_DATASOURCE_URN) == 0) {
+		tracker_result_iterator_next (iterator);
+		urn = tracker_result_iterator_value (iterator, 0);
+		if (strcmp (urn, TRACKER_NON_REMOVABLE_MEDIA_DATASOURCE_URN) == 0) {
 			/* Report non-removable media to be mounted by HAL as well */
 			state |= VOLUME_MOUNTED;
 		}
 
-		g_hash_table_insert (volumes, g_strdup (row[0]), GINT_TO_POINTER (state));
+		g_hash_table_insert (volumes, g_strdup (urn), GINT_TO_POINTER (state));
 	}
 
 	g_hash_table_replace (volumes, g_strdup (TRACKER_NON_REMOVABLE_MEDIA_DATASOURCE_URN),



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