[tracker/tracker-0.6] Fixes NB#140966, tracker-indexer D-Bus interface should have a plural FilesMove



commit 29568346d281c9c2b38be5d238ceca8785b58394
Author: Martyn Russell <martyn lanedo com>
Date:   Thu Oct 1 16:49:48 2009 +0100

    Fixes NB#140966, tracker-indexer D-Bus interface should have a plural FilesMove

 data/dbus/tracker-indexer.xml         |    6 ++
 src/tracker-indexer/tracker-indexer.c |   59 +++++++++++++++
 src/tracker-indexer/tracker-indexer.h |    6 ++
 src/trackerd/tracker-processor.c      |  126 ++++++++++++++++++++++++++------
 4 files changed, 173 insertions(+), 24 deletions(-)
---
diff --git a/data/dbus/tracker-indexer.xml b/data/dbus/tracker-indexer.xml
index ce6b1d6..c0fab6b 100644
--- a/data/dbus/tracker-indexer.xml
+++ b/data/dbus/tracker-indexer.xml
@@ -26,6 +26,12 @@
       <arg type="s" name="module" direction="in" />
       <arg type="as" name="files" direction="in" />
     </method>
+    <method name="FilesMove">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+      <arg type="s" name="module" direction="in" />
+      <arg type="as" name="files_from" direction="in" />
+      <arg type="as" name="files_to" direction="in" />
+    </method>
     <method name="FileMove">
       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
       <arg type="s" name="module" direction="in" />
diff --git a/src/tracker-indexer/tracker-indexer.c b/src/tracker-indexer/tracker-indexer.c
index 47b1769..9fcaa71 100644
--- a/src/tracker-indexer/tracker-indexer.c
+++ b/src/tracker-indexer/tracker-indexer.c
@@ -3393,6 +3393,65 @@ tracker_indexer_files_delete (TrackerIndexer *indexer,
 }
 
 void
+tracker_indexer_files_move (TrackerIndexer *indexer,
+			    const gchar *module_name,
+			    GStrv from_files,
+			    GStrv to_files,
+			    DBusGMethodInvocation *context,
+			    GError **error)
+{
+	TrackerIndexerModule *module;
+	guint request_id;
+	gint i;
+	GError *actual_error;
+
+	request_id = tracker_dbus_get_next_request_id ();
+
+	tracker_dbus_async_return_if_fail (TRACKER_IS_INDEXER (indexer), context);
+	tracker_dbus_async_return_if_fail (from_files != NULL, context);
+	tracker_dbus_async_return_if_fail (to_files != NULL, context);
+	tracker_dbus_async_return_if_fail (g_strv_length (from_files) == g_strv_length (to_files), context);
+
+	tracker_dbus_request_new (request_id,
+				  "DBus request to move %d files",
+				  g_strv_length (from_files));
+
+	module = g_hash_table_lookup (indexer->private->indexer_modules, module_name);
+
+	if (!module) {
+		tracker_dbus_request_failed (request_id,
+					     &actual_error,
+					     "The module '%s' is not loaded",
+					     module_name);
+		dbus_g_method_return_error (context, actual_error);
+		g_error_free (actual_error);
+		return;
+	}
+
+	for (i = 0; i < g_strv_length (from_files); i++) {
+		GFile *file_from, *file_to;
+		PathInfo *info;
+		const gchar *str_from, *str_to;
+
+		str_from = from_files[i];
+		str_to = to_files[i];
+
+		file_from = g_file_new_for_path (str_from);
+		file_to = g_file_new_for_path (str_to);
+		
+		/* Add files to the queue */
+		info = path_info_new (module, file_to, file_from, TRUE);
+		add_file (indexer, info);
+		
+		g_object_unref (file_from);
+		g_object_unref (file_to);
+	}
+
+	dbus_g_method_return (context);
+	tracker_dbus_request_success (request_id);
+}
+
+void
 tracker_indexer_file_move (TrackerIndexer	  *indexer,
 			   const gchar		  *module_name,
 			   gchar		  *from,
diff --git a/src/tracker-indexer/tracker-indexer.h b/src/tracker-indexer/tracker-indexer.h
index 172ca0b..0f7a076 100644
--- a/src/tracker-indexer/tracker-indexer.h
+++ b/src/tracker-indexer/tracker-indexer.h
@@ -122,6 +122,12 @@ void            tracker_indexer_files_delete        (TrackerIndexer         *ind
 						     GStrv                   files,
 						     DBusGMethodInvocation  *context,
 						     GError                **error);
+void            tracker_indexer_files_move          (TrackerIndexer         *indexer,
+						     const gchar            *module,
+						     GStrv                   from_files,
+						     GStrv                   to_files,
+						     DBusGMethodInvocation  *context,
+						     GError                **error);
 void            tracker_indexer_file_move           (TrackerIndexer         *indexer,
 						     const gchar            *module_name,
 						     gchar                  *from,
diff --git a/src/trackerd/tracker-processor.c b/src/trackerd/tracker-processor.c
index 12961a0..1cb1ee7 100644
--- a/src/trackerd/tracker-processor.c
+++ b/src/trackerd/tracker-processor.c
@@ -561,8 +561,12 @@ item_queue_count_all (TrackerProcessor *processor)
 		q = g_hash_table_lookup (processor->private->items_deleted_queues, l->data);
 		items += g_queue_get_length (q);
 
+		/* This queue has 2 items per transaction, from and
+		 * to files so we half the length for the number of
+		 * items to do in it.
+		 */
 		q = g_hash_table_lookup (processor->private->items_moved_queues, l->data);
-		items += g_queue_get_length (q);
+		items += (g_queue_get_length (q) / 2);
 	}
 
 	return items;
@@ -770,38 +774,112 @@ item_queue_handlers_cb (gpointer user_data)
 					  &module_name);
 
 	if (queue) {
-		const gchar *source;
-		const gchar *target;
+		guint length;
 
 		/* Now we try to send items to the indexer */
 		tracker_status_set_and_signal (TRACKER_STATUS_INDEXING);
 
-		files = tracker_dbus_queue_gfile_to_strv (queue, 2);
+		/* Get queue length, if length is indicates more than
+		 * one file has changed, then we call the
+		 * indexer_files_move() API instead which can handle
+		 * multiple files.
+		 */
+		length = g_queue_get_length (queue);
 
-		if (files) {
-			source = files[0];
-			target = files[1];
-		} else {
-			source = NULL;
-			target = NULL;
-		}
+		if (length > 0) {
+			gint max_items;
+			gint multiples;
 
-		g_message ("Queue for module:'%s' moved items processed, sending first %d to the indexer",
-			   module_name,
-			   g_strv_length (files));
+			multiples = length / 2;
+			max_items = MIN (length, ITEMS_QUEUE_PROCESS_MAX * 2);
 
-		processor->private->finished_indexer = FALSE;
+			if (multiples > 1) {
+				files = tracker_dbus_queue_gfile_to_strv (queue, max_items);
+			} else {
+				files = tracker_dbus_queue_gfile_to_strv (queue, 2);
+			}
 
-		processor->private->sent_type = SENT_TYPE_MOVED;
-		processor->private->sent_module_name = module_name;
-		processor->private->sent_items = files;
+			if (multiples > 1) {
+				GStrv strv_from, strv_to;
+				gint i, j;
+
+				strv_from = g_new0 (gchar*, length + 1);
+				strv_to = g_new0 (gchar*, length + 1);
+
+				/* Split items into two separate GStrvs */
+				for (i = 0, j = 0; i < max_items;) {
+					gchar *path_from, *path_to;
+
+					path_from = files[i++];
+					path_to   = files[i++];
+					
+					if (!g_utf8_validate (path_from, -1, NULL)) {
+						g_message ("Could not add string:'%s' to GStrv, invalid UTF-8", path_from);
+						g_free (path_from);
+						continue;
+					}
+
+					if (!g_utf8_validate (path_to, -1, NULL)) {
+						g_message ("Could not add string:'%s' to GStrv, invalid UTF-8", path_to);
+						g_free (path_from);
+						g_free (path_to);
+						continue;
+					}
+					
+					strv_from[j++] = path_from;
+					strv_to[j++] = path_to;
+				}
+				
+				strv_from[j] = NULL;
+				strv_to[j] = NULL;
+
+				g_message ("Queue for module:'%s' moved items processed, sending first %d to the indexer",
+					   module_name,
+					   max_items);
+				
+				processor->private->finished_indexer = FALSE;
+				
+				processor->private->sent_type = SENT_TYPE_MOVED;
+				processor->private->sent_module_name = module_name;
+				processor->private->sent_items = files;
+
+				org_freedesktop_Tracker_Indexer_files_move_async (processor->private->indexer_proxy,
+										  module_name,
+										  (const gchar**) strv_from,
+										  (const gchar**) strv_to,
+										  item_queue_processed_cb,
+										  processor);
+			} else {
+				const gchar *source;
+				const gchar *target;
+
+				if (files) {
+					source = files[0];
+					target = files[1];
+				} else {
+					source = NULL;
+					target = NULL;
+				}
+
+				g_message ("Queue for module:'%s' moved items processed, sending first %d to the indexer",
+					   module_name,
+					   g_strv_length (files));
+
+				processor->private->finished_indexer = FALSE;
+				
+				processor->private->sent_type = SENT_TYPE_MOVED;
+				processor->private->sent_module_name = module_name;
+				processor->private->sent_items = files;
+
+				org_freedesktop_Tracker_Indexer_file_move_async (processor->private->indexer_proxy,
+										 module_name,
+										 source,
+										 target,
+										 item_queue_processed_cb,
+										 processor);
 
-		org_freedesktop_Tracker_Indexer_file_move_async (processor->private->indexer_proxy,
-								 module_name,
-								 source,
-								 target,
-								 item_queue_processed_cb,
-								 processor);
+			}
+		}
 
 		return TRUE;
 	}



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