[tracker/journal: 2/3] libtracker-data: Pass ID->Class and ID->Property map to journal_replay



commit 6dbed6d5bdf2ac5dc7be728d6489ec72c8fa5931
Author: Philip Van Hoof <philip codeminded be>
Date:   Wed Mar 10 13:54:32 2010 +0100

    libtracker-data: Pass ID->Class and ID->Property map to journal_replay

 src/libtracker-data/tracker-data-manager.c |   50 +++++++++++++++++++++------
 src/libtracker-data/tracker-data-update.c  |    3 +-
 src/libtracker-data/tracker-data-update.h  |    7 ++--
 3 files changed, 45 insertions(+), 15 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index c6849c8..5b536a6 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -75,7 +75,9 @@ load_ontology_statement (const gchar *ontology_file,
                          const gchar *predicate,
                          const gchar *object,
                          gint        *max_id,
-                         gboolean    is_new)
+                         gboolean    is_new,
+                         GHashTable *classes,
+                         GHashTable *properties)
 {
 	if (g_strcmp0 (predicate, RDF_TYPE) == 0) {
 		if (g_strcmp0 (object, RDFS_CLASS) == 0) {
@@ -97,7 +99,12 @@ load_ontology_statement (const gchar *ontology_file,
 			tracker_class_set_id (class, subject_id);
 			tracker_ontologies_add_class (class);
 			tracker_ontologies_add_id_uri_pair (subject_id, subject);
-			g_object_unref (class);
+
+			if (classes) {
+				g_hash_table_insert (classes, GINT_TO_POINTER (subject_id), class);
+			} else {
+				g_object_unref (class);
+			}
 
 		} else if (g_strcmp0 (object, RDF_PROPERTY) == 0) {
 			TrackerProperty *property;
@@ -118,7 +125,12 @@ load_ontology_statement (const gchar *ontology_file,
 			tracker_property_set_id (property, subject_id);
 			tracker_ontologies_add_property (property);
 			tracker_ontologies_add_id_uri_pair (subject_id, subject);
-			g_object_unref (property);
+
+			if (properties) {
+				g_hash_table_insert (properties, GINT_TO_POINTER (subject_id), property);
+			} else {
+				g_object_unref (property);
+			}
 
 		} else if (g_strcmp0 (object, NRL_INVERSE_FUNCTIONAL_PROPERTY) == 0) {
 			TrackerProperty *property;
@@ -390,7 +402,7 @@ load_ontology_file_from_path (const gchar        *ontology_file,
 		object = tracker_turtle_reader_get_object (reader);
 
 		load_ontology_statement (ontology_file, 0, subject, predicate, object,
-		                         max_id, is_new);
+		                         max_id, is_new, NULL, NULL);
 	}
 
 	g_object_unref (reader);
@@ -491,13 +503,22 @@ load_ontology_file (const gchar               *filename,
 	g_free (ontology_file);
 }
 
-static GHashTable *
-load_ontology_from_journal (void)
+static void
+load_ontology_from_journal (GHashTable **classes_in,
+                            GHashTable **properties_in)
 {
 	GHashTable *id_uri_map;
+	GHashTable *classes, *properties;
+
+	classes = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+	                                 NULL, (GDestroyNotify) g_object_unref);
+
+	properties = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+	                                    NULL, (GDestroyNotify) g_object_unref);
 
 	id_uri_map = g_hash_table_new (g_direct_hash, g_direct_equal);
 
+
 	while (tracker_db_journal_reader_next (NULL)) {
 		TrackerDBJournalEntryType type;
 
@@ -527,13 +548,15 @@ load_ontology_from_journal (void)
 			subject = g_hash_table_lookup (id_uri_map, GINT_TO_POINTER (subject_id));
 			predicate = g_hash_table_lookup (id_uri_map, GINT_TO_POINTER (predicate_id));
 
-			load_ontology_statement ("journal", subject_id, subject, predicate, object, NULL, FALSE);
+			load_ontology_statement ("journal", subject_id, subject, predicate, 
+			                         object, NULL, FALSE, classes, properties);
 		}
 	}
 
-	g_hash_table_unref (id_uri_map);
+	*classes_in = classes;
+	*properties_in = properties;
 
-	return id_uri_map;
+	g_hash_table_unref (id_uri_map);
 }
 
 
@@ -1477,10 +1500,12 @@ tracker_data_manager_init (TrackerDBManagerFlags  flags,
 	}
 
 	if (read_journal) {
+		GHashTable *classes = NULL, *properties = NULL;
+
 		in_journal_replay = TRUE;
 
 		/* load ontology from journal into memory */
-		load_ontology_from_journal ();
+		load_ontology_from_journal (&classes, &properties);
 
 		tracker_data_begin_replay_transaction (tracker_db_journal_reader_get_time ());
 		import_ontology_into_db (FALSE);
@@ -1488,13 +1513,16 @@ tracker_data_manager_init (TrackerDBManagerFlags  flags,
 
 		tracker_db_journal_reader_shutdown ();
 
-		tracker_data_replay_journal ();
+		tracker_data_replay_journal (classes, properties);
 
 		in_journal_replay = FALSE;
 
 		/* open journal for writing */
 		tracker_db_journal_init (NULL);
 		check_ontology = TRUE;
+
+		g_hash_table_unref (classes);
+		g_hash_table_unref (properties);
 	} else if (is_first_time_index) {
 		gchar *test_schema_path = NULL;
 
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index fe6b9fb..e39b2b3 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -2427,7 +2427,8 @@ query_resource_by_id (gint id)
 }
 
 void
-tracker_data_replay_journal (void)
+tracker_data_replay_journal (GHashTable *classes,
+                             GHashTable *properties)
 {
 	GError *journal_error = NULL;
 
diff --git a/src/libtracker-data/tracker-data-update.h b/src/libtracker-data/tracker-data-update.h
index b3c88fb..7b4d7e9 100644
--- a/src/libtracker-data/tracker-data-update.h
+++ b/src/libtracker-data/tracker-data-update.h
@@ -83,13 +83,14 @@ void     tracker_data_commit_transaction            (void);
 void     tracker_data_update_sparql                 (const gchar               *update,
                                                      GError                   **error);
 GPtrArray *
-tracker_data_update_sparql_blank           (const gchar               *update,
-                                            GError                   **error);
+         tracker_data_update_sparql_blank           (const gchar               *update,
+                                                     GError                   **error);
 void     tracker_data_update_buffer_flush           (GError                   **error);
 void     tracker_data_update_buffer_might_flush     (GError                   **error);
 
 void     tracker_data_sync                          (void);
-void     tracker_data_replay_journal                (void);
+void     tracker_data_replay_journal                (GHashTable                *classes,
+                                                     GHashTable                *properties);
 
 /* Volume handling */
 void     tracker_data_update_enable_volume          (const gchar               *udi,



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