[tracker/journal] libtracker-data: Allow calling resource_buffer_switch in journal replay



commit 4ad37452c048d97084c316923afb0c275497ac0f
Author: Jürg Billeter <j bitron ch>
Date:   Thu Mar 11 17:37:31 2010 +0100

    libtracker-data: Allow calling resource_buffer_switch in journal replay

 src/libtracker-data/tracker-data-update.c |   32 +++++++++++++++++++++++-----
 1 files changed, 26 insertions(+), 6 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 8b8fba9..dcc9120 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -1413,9 +1413,19 @@ resource_buffer_switch (const gchar *graph,
                         const gchar *subject,
                         gint         subject_id)
 {
-	if (resource_buffer == NULL || strcmp (resource_buffer->subject, subject) != 0) {
-		/* switch subject */
-		resource_buffer = g_hash_table_lookup (update_buffer.resources, subject);
+	if (in_journal_replay) {
+		/* journal replay only provides subject id
+		   resource_buffer->subject is only used in error messages and callbacks
+		   both should never occur when in journal replay */
+		if (resource_buffer == NULL || resource_buffer->id != subject_id) {
+			/* switch subject */
+			resource_buffer = g_hash_table_lookup (update_buffer.resources, GINT_TO_POINTER (subject_id));
+		}
+	} else {
+		if (resource_buffer == NULL || strcmp (resource_buffer->subject, subject) != 0) {
+			/* switch subject */
+			resource_buffer = g_hash_table_lookup (update_buffer.resources, subject);
+		}
 	}
 
 	if (resource_buffer == NULL) {
@@ -1423,7 +1433,9 @@ resource_buffer_switch (const gchar *graph,
 
 		/* subject not yet in cache, retrieve or create ID */
 		resource_buffer = g_slice_new0 (TrackerDataUpdateBufferResource);
-		resource_buffer->subject = g_strdup (subject);
+		if (subject != NULL) {
+			resource_buffer->subject = g_strdup (subject);
+		}
 		if (subject_id > 0) {
 			resource_buffer->id = subject_id;
 		} else {
@@ -1438,7 +1450,11 @@ resource_buffer_switch (const gchar *graph,
 		resource_buffer->predicates = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, (GDestroyNotify) g_value_array_free);
 		resource_buffer->tables = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) cache_table_free);
 
-		g_hash_table_insert (update_buffer.resources, g_strdup (subject), resource_buffer);
+		if (in_journal_replay) {
+			g_hash_table_insert (update_buffer.resources, GINT_TO_POINTER (subject_id), resource_buffer);
+		} else {
+			g_hash_table_insert (update_buffer.resources, g_strdup (subject), resource_buffer);
+		}
 
 		g_value_init (&gvalue, G_TYPE_INT);
 		g_value_set_int (&gvalue, tracker_data_update_get_next_modseq ());
@@ -2035,7 +2051,11 @@ tracker_data_begin_transaction (void)
 
 	if (update_buffer.resource_cache == NULL) {
 		update_buffer.resource_cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
-		update_buffer.resources = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) resource_buffer_free);
+		if (in_journal_replay) {
+			update_buffer.resources = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) resource_buffer_free);
+		} else {
+			update_buffer.resources = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) resource_buffer_free);
+		}
 	}
 
 	resource_buffer = NULL;



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