[tracker/architecture-sparql-up-in-daemon] Don't perform too many statements before commit



commit 0b57d1372fe7221ce9e8a990a7d5c3bfe385bcf3
Author: Philip Van Hoof <philip codeminded be>
Date:   Mon Apr 27 15:30:06 2009 +0200

    Don't perform too many statements before commit
---
 .../evolution/tracker-evolution-registrar.c        |   29 ++++++++++++++++++-
 src/plugins/kmail/tracker-kmail-registrar.c        |   30 ++++++++++++++++++-
 2 files changed, 55 insertions(+), 4 deletions(-)

diff --git a/src/plugins/evolution/tracker-evolution-registrar.c b/src/plugins/evolution/tracker-evolution-registrar.c
index 5cf013c..fe654f7 100644
--- a/src/plugins/evolution/tracker-evolution-registrar.c
+++ b/src/plugins/evolution/tracker-evolution-registrar.c
@@ -45,6 +45,7 @@
 #define TRACKER_TYPE_EVOLUTION_PUSH_REGISTRAR    (tracker_evolution_push_registrar_get_type ())
 #define TRACKER_EVOLUTION_PUSH_REGISTRAR(module) (G_TYPE_CHECK_INSTANCE_CAST ((module), TRACKER_TYPE_EVOLUTION_PUSH_REGISTRAR, TrackerEvolutionPushRegistrar))
 
+#define TRANSACTION_MAX 200
 
 #define NIE_DATASOURCE 			       TRACKER_NIE_PREFIX "DataSource"
 #define NIE_DATASOURCE_P 		       TRACKER_NIE_PREFIX "dataSource"
@@ -552,7 +553,7 @@ tracker_evolution_registrar_set_many (TrackerEvolutionRegistrar *object,
 				      GError *derror)
 {
 	guint len;
-	guint i = 0;
+	guint i = 0, amount = 0;
 
 	dbus_async_return_if_fail (subjects != NULL, context);
 	dbus_async_return_if_fail (predicates != NULL, context);
@@ -563,17 +564,29 @@ 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);
 
+	tracker_data_begin_transaction ();
+
 	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);
 
+		amount++;
+		if (amount > TRANSACTION_MAX) {
+			tracker_data_commit_transaction ();
+			g_main_context_iteration (NULL, FALSE);
+			tracker_data_begin_transaction ();
+			amount = 0;
+		}
+
 		i++;
 	}
 
 	set_stored_last_modseq (modseq);
 
+	tracker_data_commit_transaction ();
+
 	dbus_g_method_return (context);
 }
 
@@ -584,19 +597,31 @@ tracker_evolution_registrar_unset_many (TrackerEvolutionRegistrar *object,
 					DBusGMethodInvocation *context,
 					GError *derror)
 {
-	guint i = 0;
+	guint i = 0, amount = 0;
 
 	dbus_async_return_if_fail (subjects != NULL, context);
 
+	tracker_data_begin_transaction ();
+
 	while (subjects[i] != NULL) {
 
 		perform_unset (object, subjects[i]);
 
+		amount++;
+		if (amount > TRANSACTION_MAX) {
+			tracker_data_commit_transaction ();
+			g_main_context_iteration (NULL, FALSE);
+			tracker_data_begin_transaction ();
+			amount = 0;
+		}
+
 		i++;
 	}
 
 	set_stored_last_modseq (modseq);
 
+	tracker_data_commit_transaction ();
+
 	dbus_g_method_return (context);
 }
 
diff --git a/src/plugins/kmail/tracker-kmail-registrar.c b/src/plugins/kmail/tracker-kmail-registrar.c
index abe1de7..e65892c 100644
--- a/src/plugins/kmail/tracker-kmail-registrar.c
+++ b/src/plugins/kmail/tracker-kmail-registrar.c
@@ -36,6 +36,8 @@
 
 #define __TRACKER_KMAIL_REGISTRAR_C__
 
+#define TRANSACTION_MAX 200
+
 #include "tracker-kmail-registrar.h"
 #include "tracker-kmail-registrar-glue.h"
 
@@ -334,7 +336,7 @@ tracker_kmail_registrar_set_many (TrackerKMailRegistrar *object,
 				      GError *derror)
 {
 	guint len;
-	guint i = 0;
+	guint i = 0, amount = 0;
 
 	dbus_async_return_if_fail (subjects != NULL, context);
 	dbus_async_return_if_fail (predicates != NULL, context);
@@ -345,17 +347,29 @@ 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);
 
+	tracker_data_begin_transaction ();
+
 	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);
 
+		amount++;
+		if (amount > TRANSACTION_MAX) {
+			tracker_data_commit_transaction ();
+			g_main_context_iteration (NULL, FALSE);
+			tracker_data_begin_transaction ();
+			amount = 0;
+		}
+
 		i++;
 	}
 
 	set_stored_last_modseq (modseq);
 
+	tracker_data_commit_transaction ();
+
 	dbus_g_method_return (context);
 }
 
@@ -366,19 +380,31 @@ tracker_kmail_registrar_unset_many (TrackerKMailRegistrar *object,
 				    DBusGMethodInvocation *context,
 				    GError *derror)
 {
-	guint i = 0;
+	guint i = 0, amount = 0;
 
 	dbus_async_return_if_fail (subjects != NULL, context);
 
+	tracker_data_begin_transaction ();
+
 	while (subjects[i] != NULL) {
 
 		perform_unset (object, subjects[i]);
 
+		amount++;
+		if (amount > TRANSACTION_MAX) {
+			tracker_data_commit_transaction ();
+			g_main_context_iteration (NULL, FALSE);
+			tracker_data_begin_transaction ();
+			amount = 0;
+		}
+
 		i++;
 	}
 
 	set_stored_last_modseq (modseq);
 
+	tracker_data_commit_transaction ();
+
 	dbus_g_method_return (context);
 }
 



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