[tracker/binary-log-2: 22/35] libtracker-data: Use cached ids instead of lookups



commit de52985dadfcca92f71ca51082c0e4da7e688885
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Dec 31 11:45:21 2009 +0100

    libtracker-data: Use cached ids instead of lookups

 src/libtracker-data/tracker-data-manager.c |   19 +++++++++++++--
 src/libtracker-data/tracker-data-update.c  |   33 +++++++++++++++++----------
 2 files changed, 37 insertions(+), 15 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 7988a08..0810d16 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -419,6 +419,7 @@ db_get_static_data (TrackerDBInterface *iface)
 
 			tracker_ontology_add_class (class);
 			tracker_ontology_add_id_uri_pair (id, uri);
+			tracker_class_set_id (class, id);
 
 			/* xsd classes do not derive from rdfs:Resource and do not use separate tables */
 			if (!g_str_has_prefix (tracker_class_get_name (class), "xsd:")) {
@@ -532,6 +533,7 @@ db_get_static_data (TrackerDBInterface *iface)
 
 			tracker_property_set_transient (property, transient);
 			tracker_property_set_uri (property, uri);
+			tracker_property_set_id (property, id);
 			tracker_property_set_domain (property, tracker_ontology_get_class_by_uri (domain_uri));
 			tracker_property_set_range (property, tracker_ontology_get_class_by_uri (range_uri));
 			tracker_property_set_multiple_values (property, multi_valued);
@@ -543,7 +545,7 @@ db_get_static_data (TrackerDBInterface *iface)
 
 			tracker_ontology_add_property (property);
 			tracker_ontology_add_id_uri_pair (id, uri);
-
+			
 			g_object_unref (property);
 
 		}
@@ -554,7 +556,11 @@ db_get_static_data (TrackerDBInterface *iface)
 
 
 static void
-insert_uri_in_resource_table (TrackerDBInterface *iface, const gchar *uri, gint *max_id)
+insert_uri_in_resource_table (TrackerDBInterface *iface, 
+                              const gchar *uri, 
+                              gint *max_id,
+                              TrackerClass *class,
+                              TrackerProperty *property)
 {
 	TrackerDBStatement *stmt;
 	gint id = ++(*max_id);
@@ -578,6 +584,13 @@ insert_uri_in_resource_table (TrackerDBInterface *iface, const gchar *uri, gint
 
 	tracker_db_journal_append_resource (id, uri);
 	tracker_ontology_add_id_uri_pair (id, uri);
+
+	if (class)
+		tracker_class_set_id (class, id);
+
+	if (property)
+		tracker_property_set_id (property, id);
+
 	g_object_unref (stmt);
 
 }
@@ -901,7 +914,7 @@ tracker_data_manager_init (TrackerDBManagerFlags  flags,
 
 		for (i = 0; i < n_props; i++) {
 			insert_uri_in_resource_table (iface, tracker_property_get_uri (properties[i]),
-			                              &max_id);
+			                              &max_id, NULL, properties[i]);
 		}
 
 		create_fts_table (iface);
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index b5e8a4f..aeabdb9 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -1292,13 +1292,14 @@ tracker_data_delete_statement (const gchar  *graph,
 	} else {
 		field = tracker_ontology_get_property_by_uri (predicate);
 		if (field != NULL) {
+			guint32 id = tracker_property_get_id (field);
 			if (tracker_property_get_data_type (field) == TRACKER_PROPERTY_TYPE_RESOURCE) {
 				tracker_db_journal_append_delete_statement_code (resource_buffer->id,
-					tracker_data_query_resource_id (predicate),
+					(id != 0) ? id : tracker_data_query_resource_id (predicate),
 					query_resource_id (object));
 			} else {
 				tracker_db_journal_append_delete_statement (resource_buffer->id,
-					tracker_data_query_resource_id (predicate),
+					(id != 0) ? id : tracker_data_query_resource_id (predicate),
 					object);
 			}
 
@@ -1439,6 +1440,7 @@ tracker_data_insert_statement_with_uri (const gchar            *graph,
 	GError          *actual_error = NULL;
 	TrackerClass    *class;
 	TrackerProperty *property;
+	guint32          prop_id = 0;
 
 	g_return_if_fail (subject != NULL);
 	g_return_if_fail (predicate != NULL);
@@ -1454,10 +1456,13 @@ tracker_data_insert_statement_with_uri (const gchar            *graph,
 			             "Property '%s' not found in the ontology", predicate);
 			return;
 		}
-	} else if (tracker_property_get_data_type (property) != TRACKER_PROPERTY_TYPE_RESOURCE) {
-		g_set_error (error, TRACKER_DATA_ERROR, TRACKER_DATA_ERROR_INVALID_TYPE,
-		             "Property '%s' does not accept URIs", predicate);
-		return;
+	} else {
+		if (tracker_property_get_data_type (property) != TRACKER_PROPERTY_TYPE_RESOURCE) {
+			g_set_error (error, TRACKER_DATA_ERROR, TRACKER_DATA_ERROR_INVALID_TYPE,
+			             "Property '%s' does not accept URIs", predicate);
+			return;
+		}
+		prop_id = tracker_property_get_id (property);
 	}
 
 	/* subjects and objects starting with `:' are anonymous blank nodes */
@@ -1541,7 +1546,7 @@ tracker_data_insert_statement_with_uri (const gchar            *graph,
 	}
 
 	tracker_db_journal_append_insert_statement_code (resource_buffer->id,
-		tracker_data_query_resource_id (predicate),
+		(prop_id != 0) ? prop_id : tracker_data_query_resource_id (predicate),
 		query_resource_id (object));
 }
 
@@ -1554,6 +1559,7 @@ tracker_data_insert_statement_with_string (const gchar            *graph,
 {
 	GError          *actual_error = NULL;
 	TrackerProperty *property;
+	guint32          id = 0;
 
 	g_return_if_fail (subject != NULL);
 	g_return_if_fail (predicate != NULL);
@@ -1565,10 +1571,13 @@ tracker_data_insert_statement_with_string (const gchar            *graph,
 		g_set_error (error, TRACKER_DATA_ERROR, TRACKER_DATA_ERROR_UNKNOWN_PROPERTY,
 		             "Property '%s' not found in the ontology", predicate);
 		return;
-	} else if (tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_RESOURCE) {
-		g_set_error (error, TRACKER_DATA_ERROR, TRACKER_DATA_ERROR_INVALID_TYPE,
-		             "Property '%s' only accepts URIs", predicate);
-		return;
+	} else {
+		if (tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_RESOURCE) {
+			g_set_error (error, TRACKER_DATA_ERROR, TRACKER_DATA_ERROR_INVALID_TYPE,
+			             "Property '%s' only accepts URIs", predicate);
+			return;
+		}
+		id = tracker_property_get_id (property);
 	}
 
 	if (!tracker_data_insert_statement_common (graph, subject, predicate, object, &actual_error)) {
@@ -1601,7 +1610,7 @@ tracker_data_insert_statement_with_string (const gchar            *graph,
 	}
 
 	tracker_db_journal_append_insert_statement (resource_buffer->id,
-		tracker_data_query_resource_id (predicate),
+		(id != 0) ? id : tracker_data_query_resource_id (predicate),
 		object);
 }
 



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