[tracker/tracker-store] Don't do all the g_idle_add nonsense in the push modules



commit aa4b5e4a25ef1c0b9ee4e1fac9a46ee3ade1a950
Author: Philip Van Hoof <philip codeminded be>
Date:   Mon Jun 15 00:39:08 2009 +0200

    Don't do all the g_idle_add nonsense in the push modules
    
    These were causing a GSource source for each 2000 items being pushed using the
    DBus SetMany() call. Making it actually worse than better. I just removed them
    for now, we might have to replace it with an internal, but static global for
    the module, queue (not a queue per SetMany, like what is being removed here).

 .../evolution/tracker-evolution-registrar.c        |  158 ++-----------------
 src/plugins/kmail/tracker-kmail-registrar.c        |  156 ++-----------------
 2 files changed, 34 insertions(+), 280 deletions(-)
---
diff --git a/src/plugins/evolution/tracker-evolution-registrar.c b/src/plugins/evolution/tracker-evolution-registrar.c
index c92dfc0..31be1ea 100644
--- a/src/plugins/evolution/tracker-evolution-registrar.c
+++ b/src/plugins/evolution/tracker-evolution-registrar.c
@@ -639,84 +639,10 @@ tracker_evolution_registrar_set (TrackerEvolutionRegistrar *object,
 	dbus_g_method_return (context);
 }
 
-
-
-typedef struct {
-	TrackerEvolutionRegistrar *object;
-	GStrv subjects;
-	GPtrArray *predicates;
-	GPtrArray *values;
-	guint modseq;
-	DBusGMethodInvocation *context;
-} SetManyInfo;
-
-static gboolean
-set_many_idle (gpointer user_data)
-{
-	guint i = 0;
-	SetManyInfo *info = user_data;
-	gboolean cont = FALSE;
-
-	while (info->subjects[i] != NULL) {
-		GStrv preds = g_ptr_array_index (info->predicates, i);
-		GStrv vals = g_ptr_array_index (info->values, i);
-
-		perform_set (info->object, info->subjects[i], preds, vals);
-
-		if (i > 100) {
-			cont = TRUE;
-			break;
-		}
-
-		i++;
-	}
-
-	return cont;
-}
-
 static void
-strv_ptrarray_free (GPtrArray *array)
-{
-	guint i;
-
-	for (i = 0; i < array->len; i++) {
-		g_strfreev (g_ptr_array_index (array, i));
-	}
-
-	g_ptr_array_free (array, TRUE);
-}
-
-static void 
-set_many_destroy (gpointer user_data)
-{
-	SetManyInfo *info = user_data;
-
-	strv_ptrarray_free (info->predicates);
-	strv_ptrarray_free (info->values);
-	g_strfreev (info->subjects);
-
-	set_stored_last_modseq (info->modseq);
-
-	tracker_store_queue_commit (NULL, NULL, NULL);
-
-	dbus_g_method_return (info->context);
-
-	g_object_unref (info->object);
-	g_free (info);
-}
-
-static GPtrArray* 
-strv_ptrarray_dup (const GPtrArray *array)
+on_commit (gpointer user_data)
 {
-	GPtrArray *new_array = g_ptr_array_sized_new (array->len);
-	guint i;
-
-	for (i = 0; i < array->len; i++) {
-		g_ptr_array_add	(new_array, g_strdupv (
-		                 g_ptr_array_index (array, i)));
-	}
-
-	return new_array;
+	set_stored_last_modseq (GPOINTER_TO_UINT (user_data));
 }
 
 void
@@ -728,8 +654,7 @@ tracker_evolution_registrar_set_many (TrackerEvolutionRegistrar *object,
 				      DBusGMethodInvocation *context,
 				      GError *derror)
 {
-	guint len;
-	SetManyInfo *info;
+	guint len, i = 0;
 
 	dbus_async_return_if_fail (subjects != NULL, context);
 	dbus_async_return_if_fail (predicates != NULL, context);
@@ -740,65 +665,19 @@ tracker_evolution_registrar_set_many (TrackerEvolutionRegistrar *object,
 	dbus_async_return_if_fail (len == predicates->len, context);
 	dbus_async_return_if_fail (len == values->len, context);
 
-	info = g_new0 (SetManyInfo, 1);
-
-	info->object = g_object_ref (object);
-	info->context = context;
-	info->modseq = modseq;
-	info->subjects = g_strdupv (subjects);
-	info->predicates = strv_ptrarray_dup (predicates);
-	info->values = strv_ptrarray_dup (values);
-
-	g_idle_add_full (G_PRIORITY_LOW,
-	                 set_many_idle,
-	                 info,
-	                 set_many_destroy);
-}
-
-
-typedef struct {
-	GStrv subjects;
-	guint modseq;
-	DBusGMethodInvocation *context;
-	TrackerEvolutionRegistrar *object;
-} UnsetManyInfo;
-
-static gboolean
-unset_many_idle (gpointer user_data)
-{
-	guint i = 0;
-	gboolean cont = FALSE;
-	UnsetManyInfo *info = user_data;
-
-	while (info->subjects[i] != NULL) {
-
-		perform_unset (info->object, info->subjects[i], TRUE);
-
-		if (i > 100) {
-			cont = TRUE;
-			break;
-		}
-
+	while (subjects[i] != NULL) {
+		GStrv preds = g_ptr_array_index (predicates, i);
+		GStrv vals = g_ptr_array_index (values, i);
+		perform_set (object, subjects[i], preds, vals);
 		i++;
 	}
 
-	return cont;
-}
-
-static void
-unset_many_destroy (gpointer user_data)
-{
-	UnsetManyInfo *info = user_data;
+	tracker_store_queue_commit (on_commit, GUINT_TO_POINTER (modseq), NULL);
 
-	set_stored_last_modseq (info->modseq);
-
-	tracker_store_queue_commit (NULL, NULL, NULL);
+	dbus_g_method_return (context);
+}
 
-	dbus_g_method_return (info->context);
 
-	g_object_unref (info->object);
-	g_free (info);
-}
 
 void
 tracker_evolution_registrar_unset_many (TrackerEvolutionRegistrar *object, 
@@ -807,21 +686,18 @@ tracker_evolution_registrar_unset_many (TrackerEvolutionRegistrar *object,
 					DBusGMethodInvocation *context,
 					GError *derror)
 {
-	UnsetManyInfo *info;
+	guint i = 0;
 
 	dbus_async_return_if_fail (subjects != NULL, context);
 
-	info = g_new0 (UnsetManyInfo, 1);
+	while (subjects[i] != NULL) {
+		perform_unset (object, subjects[i], TRUE);
+		i++;
+	}
 
-	info->object = g_object_ref (object);
-	info->context = context;
-	info->modseq = modseq;
-	info->subjects = g_strdupv (subjects);
+	tracker_store_queue_commit (on_commit, GUINT_TO_POINTER (modseq), NULL);
 
-	g_idle_add_full (G_PRIORITY_LOW,
-	                 unset_many_idle,
-	                 info,
-	                 unset_many_destroy);
+	dbus_g_method_return (context);
 }
 
 void
diff --git a/src/plugins/kmail/tracker-kmail-registrar.c b/src/plugins/kmail/tracker-kmail-registrar.c
index 38cda7e..e5f402b 100644
--- a/src/plugins/kmail/tracker-kmail-registrar.c
+++ b/src/plugins/kmail/tracker-kmail-registrar.c
@@ -403,82 +403,10 @@ tracker_kmail_registrar_set (TrackerKMailRegistrar *object,
 	dbus_g_method_return (context);
 }
 
-typedef struct {
-	TrackerKMailRegistrar *object;
-	GStrv subjects;
-	GPtrArray *predicates;
-	GPtrArray *values;
-	guint modseq;
-	DBusGMethodInvocation *context;
-} SetManyInfo;
-
-static gboolean
-set_many_idle (gpointer user_data)
-{
-	guint i = 0;
-	SetManyInfo *info = user_data;
-	gboolean cont = FALSE;
-
-	while (info->subjects[i] != NULL) {
-		GStrv preds = g_ptr_array_index (info->predicates, i);
-		GStrv vals = g_ptr_array_index (info->values, i);
-
-		perform_set (info->object, info->subjects[i], preds, vals);
-
-		if (i > 100) {
-			cont = TRUE;
-			break;
-		}
-
-		i++;
-	}
-
-	return cont;
-}
-
 static void
-strv_ptrarray_free (GPtrArray *array)
-{
-	guint i;
-
-	for (i = 0; i < array->len; i++) {
-		g_strfreev (g_ptr_array_index (array, i));
-	}
-
-	g_ptr_array_free (array, TRUE);
-}
-
-static void 
-set_many_destroy (gpointer user_data)
-{
-	SetManyInfo *info = user_data;
-
-	strv_ptrarray_free (info->predicates);
-	strv_ptrarray_free (info->values);
-	g_strfreev (info->subjects);
-
-	set_stored_last_modseq (info->modseq);
-
-	tracker_store_queue_commit (NULL, NULL, NULL);
-
-	dbus_g_method_return (info->context);
-
-	g_object_unref (info->object);
-	g_free (info);
-}
-
-static GPtrArray* 
-strv_ptrarray_dup (const GPtrArray *array)
+on_commit (gpointer user_data)
 {
-	GPtrArray *new_array = g_ptr_array_sized_new (array->len);
-	guint i;
-
-	for (i = 0; i < array->len; i++) {
-		g_ptr_array_add	(new_array, g_strdupv (
-		                 g_ptr_array_index (array, i)));
-	}
-
-	return new_array;
+	set_stored_last_modseq (GPOINTER_TO_UINT (user_data));
 }
 
 void
@@ -490,8 +418,7 @@ tracker_kmail_registrar_set_many (TrackerKMailRegistrar *object,
 				      DBusGMethodInvocation *context,
 				      GError *derror)
 {
-	guint len;
-	SetManyInfo *info;
+	guint len, i = 0;
 
 	dbus_async_return_if_fail (subjects != NULL, context);
 	dbus_async_return_if_fail (predicates != NULL, context);
@@ -502,65 +429,19 @@ tracker_kmail_registrar_set_many (TrackerKMailRegistrar *object,
 	dbus_async_return_if_fail (len == predicates->len, context);
 	dbus_async_return_if_fail (len == values->len, context);
 
-	info = g_new0 (SetManyInfo, 1);
-
-	info->object = g_object_ref (object);
-	info->context = context;
-	info->modseq = modseq;
-	info->subjects = g_strdupv (subjects);
-	info->predicates = strv_ptrarray_dup (predicates);
-	info->values = strv_ptrarray_dup (values);
-
-	g_idle_add_full (G_PRIORITY_LOW,
-	                 set_many_idle,
-	                 info,
-	                 set_many_destroy);
-
-}
-
-typedef struct {
-	GStrv subjects;
-	guint modseq;
-	DBusGMethodInvocation *context;
-	TrackerKMailRegistrar *object;
-} UnsetManyInfo;
-
-static gboolean
-unset_many_idle (gpointer user_data)
-{
-	guint i = 0;
-	gboolean cont = FALSE;
-	UnsetManyInfo *info = user_data;
-
-	while (info->subjects[i] != NULL) {
-
-		perform_unset (info->object, info->subjects[i], TRUE);
-
-		if (i > 100) {
-			cont = TRUE;
-			break;
-		}
-
+	while (subjects[i] != NULL) {
+		GStrv preds = g_ptr_array_index (predicates, i);
+		GStrv vals = g_ptr_array_index (values, i);
+		perform_set (object, subjects[i], preds, vals);
 		i++;
 	}
 
-	return cont;
-}
+	tracker_store_queue_commit (on_commit, GUINT_TO_POINTER (modseq), NULL);
 
-static void
-unset_many_destroy (gpointer user_data)
-{
-	UnsetManyInfo *info = user_data;
-
-	set_stored_last_modseq (info->modseq);
-
-	tracker_store_queue_commit (NULL, NULL, NULL);
+	dbus_g_method_return (context);
+}
 
-	dbus_g_method_return (info->context);
 
-	g_object_unref (info->object);
-	g_free (info);
-}
 
 void
 tracker_kmail_registrar_unset_many (TrackerKMailRegistrar *object, 
@@ -569,21 +450,18 @@ tracker_kmail_registrar_unset_many (TrackerKMailRegistrar *object,
 				    DBusGMethodInvocation *context,
 				    GError *derror)
 {
-	UnsetManyInfo *info;
+	guint i = 0;
 
 	dbus_async_return_if_fail (subjects != NULL, context);
 
-	info = g_new0 (UnsetManyInfo, 1);
+	while (subjects[i] != NULL) {
+		perform_unset (object, subjects[i], TRUE);
+		i++;
+	}
 
-	info->object = g_object_ref (object);
-	info->context = context;
-	info->modseq = modseq;
-	info->subjects = g_strdupv (subjects);
+	tracker_store_queue_commit (on_commit, GUINT_TO_POINTER (modseq), NULL);
 
-	g_idle_add_full (G_PRIORITY_LOW,
-	                 unset_many_idle,
-	                 info,
-	                 unset_many_destroy);
+	dbus_g_method_return (context);
 }
 
 void



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