[tracker/miner-web-review] libtracker-data: Fix journal replay with insert/delete mix



commit e1befbd97100486f6e1b0f360cadaf5bccaf0e44
Author: Jürg Billeter <j bitron ch>
Date:   Tue Mar 16 12:34:27 2010 +0100

    libtracker-data: Fix journal replay with insert/delete mix

 src/libtracker-data/tracker-data-update.c |   45 +++++++++++++++++++++++++++--
 1 files changed, 42 insertions(+), 3 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 94bb601..27e76c0 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -2405,6 +2405,7 @@ tracker_data_replay_journal (GHashTable *classes,
 {
 	GError *journal_error = NULL;
 	static TrackerProperty *rdf_type = NULL;
+	gint last_operation_type = 0;
 
 	if (!rdf_type) {
 		rdf_type = tracker_ontologies_get_property_by_uri (RDF_PREFIX "type");
@@ -2457,22 +2458,30 @@ tracker_data_replay_journal (GHashTable *classes,
 		} else if (type == TRACKER_DB_JOURNAL_END_TRANSACTION) {
 			tracker_data_commit_transaction ();
 		} else if (type == TRACKER_DB_JOURNAL_INSERT_STATEMENT) {
+			GError *new_error = NULL;
 			TrackerProperty *property;
 
+			if (last_operation_type == -1) {
+				tracker_data_update_buffer_flush (&new_error);
+				if (new_error) {
+					g_warning ("Journal replay error: '%s'", new_error->message);
+					g_clear_error (&new_error);
+				}
+			}
+			last_operation_type = 1;
+
 			tracker_db_journal_reader_get_statement (&graph_id, &subject_id, &predicate_id, &object);
 
 			property = g_hash_table_lookup (properties, GINT_TO_POINTER (predicate_id));
 
 			if (property) {
-				GError *new_error = NULL;
-
 				resource_buffer_switch (NULL, graph_id, NULL, subject_id);
 
 				cache_set_metadata_decomposed (property, object, 0, NULL, graph_id, &new_error);
 
 				if (new_error) {
 					g_warning ("Journal replay error: '%s'", new_error->message);
-					g_error_free (new_error);
+					g_clear_error (&new_error);
 				}
 
 			} else {
@@ -2480,9 +2489,19 @@ tracker_data_replay_journal (GHashTable *classes,
 			}
 
 		} else if (type == TRACKER_DB_JOURNAL_INSERT_STATEMENT_ID) {
+			GError *new_error = NULL;
 			TrackerClass *class = NULL;
 			TrackerProperty *property;
 
+			if (last_operation_type == -1) {
+				tracker_data_update_buffer_flush (&new_error);
+				if (new_error) {
+					g_warning ("Journal replay error: '%s'", new_error->message);
+					g_clear_error (&new_error);
+				}
+			}
+			last_operation_type = 1;
+
 			tracker_db_journal_reader_get_statement_id (&graph_id, &subject_id, &predicate_id, &object_id);
 
 			property = g_hash_table_lookup (properties, GINT_TO_POINTER (predicate_id));
@@ -2518,8 +2537,18 @@ tracker_data_replay_journal (GHashTable *classes,
 			}
 
 		} else if (type == TRACKER_DB_JOURNAL_DELETE_STATEMENT) {
+			GError *new_error = NULL;
 			TrackerProperty *property;
 
+			if (last_operation_type == 1) {
+				tracker_data_update_buffer_flush (&new_error);
+				if (new_error) {
+					g_warning ("Journal replay error: '%s'", new_error->message);
+					g_clear_error (&new_error);
+				}
+			}
+			last_operation_type = -1;
+
 			tracker_db_journal_reader_get_statement (&graph_id, &subject_id, &predicate_id, &object);
 
 			resource_buffer_switch (NULL, graph_id, NULL, subject_id);
@@ -2552,9 +2581,19 @@ tracker_data_replay_journal (GHashTable *classes,
 			}
 
 		} else if (type == TRACKER_DB_JOURNAL_DELETE_STATEMENT_ID) {
+			GError *new_error = NULL;
 			TrackerClass *class = NULL;
 			TrackerProperty *property;
 
+			if (last_operation_type == 1) {
+				tracker_data_update_buffer_flush (&new_error);
+				if (new_error) {
+					g_warning ("Journal replay error: '%s'", new_error->message);
+					g_clear_error (&new_error);
+				}
+			}
+			last_operation_type = -1;
+
 			tracker_db_journal_reader_get_statement_id (&graph_id, &subject_id, &predicate_id, &object_id);
 
 			property = g_hash_table_lookup (properties, GINT_TO_POINTER (predicate_id));



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