[tracker] tracker-store, libtracker-data: Enhance signal behaviour for batch updates



commit ad79e6369ccc3f46b4bf291f6e4a6b60a5b3606d
Author: Philip Van Hoof <philip codeminded be>
Date:   Fri Dec 17 11:53:05 2010 +0100

    tracker-store, libtracker-data: Enhance signal behaviour for batch updates

 src/libtracker-data/tracker-data-update.c |    6 ++--
 src/libtracker-data/tracker-data-update.h |    5 ++-
 src/tracker-store/tracker-resources.c     |    8 ++++--
 src/tracker-store/tracker-store.c         |   34 +++++++++++++++++++++++++---
 4 files changed, 41 insertions(+), 12 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 7f9e6d1..9f6dc33 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -2353,14 +2353,14 @@ tracker_data_commit_transaction (GError **error)
 }
 
 void
-tracker_data_notify_transaction (void)
+tracker_data_notify_transaction (gboolean start_timer)
 {
 	if (commit_callbacks) {
 		guint n;
 		for (n = 0; n < commit_callbacks->len; n++) {
 			TrackerCommitDelegate *delegate;
 			delegate = g_ptr_array_index (commit_callbacks, n);
-			delegate->callback (delegate->user_data);
+			delegate->callback (start_timer, delegate->user_data);
 		}
 	}
 }
@@ -2646,7 +2646,7 @@ tracker_data_rollback_transaction (void)
 		for (n = 0; n < rollback_callbacks->len; n++) {
 			TrackerCommitDelegate *delegate;
 			delegate = g_ptr_array_index (rollback_callbacks, n);
-			delegate->callback (delegate->user_data);
+			delegate->callback (TRUE, delegate->user_data);
 		}
 	}
 }
diff --git a/src/libtracker-data/tracker-data-update.h b/src/libtracker-data/tracker-data-update.h
index 343674f..61d39f0 100644
--- a/src/libtracker-data/tracker-data-update.h
+++ b/src/libtracker-data/tracker-data-update.h
@@ -43,7 +43,8 @@ typedef void (*TrackerStatementCallback) (gint         graph_id,
                                           const gchar *object,
                                           GPtrArray   *rdf_types,
                                           gpointer     user_data);
-typedef void (*TrackerCommitCallback)    (gpointer     user_data);
+typedef void (*TrackerCommitCallback)    (gboolean     start_timer,
+                                          gpointer     user_data);
 
 GQuark   tracker_data_error_quark                   (void);
 
@@ -76,7 +77,7 @@ void     tracker_data_begin_ontology_transaction    (GError                   **
 void     tracker_data_begin_transaction_for_replay  (time_t                     time,
                                                      GError                   **error);
 void     tracker_data_commit_transaction            (GError                   **error);
-void     tracker_data_notify_transaction            (void);
+void     tracker_data_notify_transaction            (gboolean                   start_timer);
 void     tracker_data_rollback_transaction          (void);
 void     tracker_data_update_sparql                 (const gchar               *update,
                                                      GError                   **error);
diff --git a/src/tracker-store/tracker-resources.c b/src/tracker-store/tracker-resources.c
index e775e3a..06fcb47 100644
--- a/src/tracker-store/tracker-resources.c
+++ b/src/tracker-store/tracker-resources.c
@@ -643,7 +643,8 @@ on_emit_signals (gpointer user_data)
 }
 
 static void
-on_statements_committed (gpointer user_data)
+on_statements_committed (gboolean start_timer,
+                         gpointer user_data)
 {
 	TrackerResources *resources = user_data;
 	TrackerResourcesPrivate *priv;
@@ -662,7 +663,7 @@ on_statements_committed (gpointer user_data)
 		tracker_class_transact_events (class);
 	}
 
-	if (priv->signal_timeout == 0) {
+	if (start_timer && priv->signal_timeout == 0) {
 		priv->signal_timeout = g_timeout_add_seconds (TRACKER_SIGNALS_SECONDS_PER_EMIT,
 		                                              on_emit_signals,
 		                                              user_data);
@@ -674,7 +675,8 @@ on_statements_committed (gpointer user_data)
 
 
 static void
-on_statements_rolled_back (gpointer user_data)
+on_statements_rolled_back (gboolean start_timer,
+                           gpointer user_data)
 {
 	tracker_events_reset_pending ();
 	tracker_writeback_reset_pending ();
diff --git a/src/tracker-store/tracker-store.c b/src/tracker-store/tracker-store.c
index 7e8228b..28a4172 100644
--- a/src/tracker-store/tracker-store.c
+++ b/src/tracker-store/tracker-store.c
@@ -78,9 +78,10 @@ typedef struct {
 		struct {
 			gchar        *query;
 			GPtrArray    *blank_nodes;
+			TrackerStorePriority priority;
 		} update;
 		struct {
-			gchar               *path;
+			gchar        *path;
 		} turtle;
 	} data;
 	gchar                *client_id;
@@ -205,6 +206,30 @@ sched (TrackerStorePrivate *private)
 }
 
 static gboolean
+start_timer_or_not (TrackerStorePrivate *private,
+                    TrackerStoreTask    *task)
+{
+	gboolean result;
+
+	switch (task->type) {
+		case TRACKER_STORE_TASK_TYPE_UPDATE:
+		case TRACKER_STORE_TASK_TYPE_UPDATE_BLANK:
+			result = !(task->data.update.priority == TRACKER_STORE_PRIORITY_LOW &&
+			           g_queue_get_length (private->update_queues[TRACKER_STORE_PRIORITY_LOW]) > 0);
+			break;
+		case TRACKER_STORE_TASK_TYPE_TURTLE:
+			result = g_queue_get_length (private->update_queues[TRACKER_STORE_PRIORITY_TURTLE]) == 0;
+			break;
+		case TRACKER_STORE_TASK_TYPE_QUERY:
+		default:
+			result = FALSE;
+			break;
+	}
+
+	return result;
+}
+
+static gboolean
 task_finish_cb (gpointer data)
 {
 	TrackerStorePrivate *private;
@@ -230,7 +255,7 @@ task_finish_cb (gpointer data)
 		private->n_queries_running--;
 	} else if (task->type == TRACKER_STORE_TASK_TYPE_UPDATE) {
 		if (!task->error) {
-			tracker_data_notify_transaction ();
+			tracker_data_notify_transaction (start_timer_or_not (private, task));
 		}
 
 		if (task->callback.update_callback) {
@@ -244,7 +269,7 @@ task_finish_cb (gpointer data)
 		private->update_running = FALSE;
 	} else if (task->type == TRACKER_STORE_TASK_TYPE_UPDATE_BLANK) {
 		if (!task->error) {
-			tracker_data_notify_transaction ();
+			tracker_data_notify_transaction (start_timer_or_not (private, task));
 		}
 
 		if (task->callback.update_blank_callback) {
@@ -273,7 +298,7 @@ task_finish_cb (gpointer data)
 		private->update_running = FALSE;
 	} else if (task->type == TRACKER_STORE_TASK_TYPE_TURTLE) {
 		if (!task->error) {
-			tracker_data_notify_transaction ();
+			tracker_data_notify_transaction (start_timer_or_not (private, task));
 		}
 
 		if (task->callback.turtle_callback) {
@@ -482,6 +507,7 @@ tracker_store_sparql_update (const gchar *sparql,
 	task = g_slice_new0 (TrackerStoreTask);
 	task->type = TRACKER_STORE_TASK_TYPE_UPDATE;
 	task->data.update.query = g_strdup (sparql);
+	task->data.update.priority = priority;
 	task->user_data = user_data;
 	task->callback.update_callback = callback;
 	task->destroy = destroy;



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