[tracker/domain-specific-indexes] libtracker-data: Only write to the domain-index class if the resource is one of them



commit b7fe34f98195f5eb862c321bf1bec09b83cbfbc5
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Jul 1 15:50:59 2010 +0200

    libtracker-data: Only write to the domain-index class if the resource is one of them

 src/libtracker-data/tracker-data-manager.c |    5 +-
 src/libtracker-data/tracker-data-update.c  |   84 ++++++++++++++++++----------
 src/libtracker-data/tracker-property.c     |   21 +++----
 src/libtracker-data/tracker-property.h     |    4 +-
 4 files changed, 68 insertions(+), 46 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index ce4d339..817a687 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -560,7 +560,7 @@ tracker_data_ontology_load_statement (const gchar *ontology_path,
 		if (!ignore) {
 			tracker_property_set_is_new_domain_index (property, in_update);
 			tracker_class_add_domain_index (class, property);
-			tracker_property_set_domain_index (property, class);
+			tracker_property_add_domain_index (property, class);
 		}
 
 	} else if (g_strcmp0 (predicate, TRACKER_PREFIX "writeback") == 0) {
@@ -1305,7 +1305,7 @@ class_add_domain_indexes_from_db (TrackerDBInterface *iface,
 			domain_index_uri = tracker_db_cursor_get_string (cursor, 0, NULL);
 			domain_index = tracker_ontologies_get_property_by_uri (domain_index_uri);
 			tracker_class_add_domain_index (class, domain_index);
-			tracker_property_set_domain_index (domain_index, class);
+			tracker_property_add_domain_index (domain_index, class);
 		}
 
 		g_object_unref (cursor);
@@ -1640,7 +1640,6 @@ db_get_static_data (TrackerDBInterface *iface)
 
 			default_value = tracker_db_cursor_get_string (cursor, 13, NULL);
 
-			tracker_property_set_domain_index (property, NULL);
 			tracker_property_set_is_new_domain_index (property, FALSE);
 			tracker_property_set_is_new (property, FALSE);
 			tracker_property_set_transient (property, transient);
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index f33a4e8..6df955c 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -1349,6 +1349,21 @@ string_to_gvalue (const gchar         *value,
 }
 
 static gboolean
+resource_in_domain_index (TrackerClass **domain_index_classes)
+{
+	while (*domain_index_classes) {
+		guint i;
+		for (i = 0; i < resource_buffer->types->len; i++) {
+			if (g_ptr_array_index (resource_buffer->types, i) == *domain_index_classes) {
+				return TRUE;
+			}
+		}
+		domain_index_classes++;
+	}
+	return FALSE;
+}
+
+static gboolean
 cache_set_metadata_decomposed (TrackerProperty  *property,
                                const gchar      *value,
                                gint              value_id,
@@ -1442,21 +1457,24 @@ cache_set_metadata_decomposed (TrackerProperty  *property,
 		                    tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_DATETIME);
 
 		if (!multiple_values) {
-			TrackerClass *domain_index_class;
+			TrackerClass **domain_index_classes;
 
-			domain_index_class = tracker_property_get_domain_index (property);
+			domain_index_classes = tracker_property_get_domain_indexes (property);
 
-			if (domain_index_class) {
-				GValue gvalue_copy = { 0 };
+			if (resource_in_domain_index (domain_index_classes)) {
+				while (*domain_index_classes) {
+					GValue gvalue_copy = { 0 };
 
-				g_value_init (&gvalue_copy, G_VALUE_TYPE (&gvalue));
-				g_value_copy (&gvalue, &gvalue_copy);
+					g_value_init (&gvalue_copy, G_VALUE_TYPE (&gvalue));
+					g_value_copy (&gvalue, &gvalue_copy);
 
-				cache_insert_value (tracker_class_get_name (domain_index_class), field_name, &gvalue_copy,
-				                    graph != NULL ? ensure_resource_id (graph, NULL) : graph_id,
-				                    multiple_values,
-				                    tracker_property_get_fulltext_indexed (property),
-				                    tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_DATETIME);
+					cache_insert_value (tracker_class_get_name (*domain_index_classes), field_name, &gvalue_copy,
+					                    graph != NULL ? ensure_resource_id (graph, NULL) : graph_id,
+					                    multiple_values,
+					                    tracker_property_get_fulltext_indexed (property),
+					                    tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_DATETIME);
+					domain_index_classes++;
+				}
 			}
 		}
 
@@ -1512,19 +1530,23 @@ delete_metadata_decomposed (TrackerProperty  *property,
 		                    tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_DATETIME);
 
 		if (!multiple_values) {
-			TrackerClass *domain_index_class;
+			TrackerClass **domain_index_classes;
+
+			domain_index_classes = tracker_property_get_domain_indexes (property);
 
-			domain_index_class = tracker_property_get_domain_index (property);
+			if (resource_in_domain_index (domain_index_classes)) {
+				while (*domain_index_classes) {
+					GValue gvalue_copy = { 0 };
 
-			if (domain_index_class) {
-				GValue gvalue_copy = { 0 };
+					g_value_init (&gvalue_copy, G_VALUE_TYPE (&gvalue));
+					g_value_copy (&gvalue, &gvalue_copy);
 
-				g_value_init (&gvalue_copy, G_VALUE_TYPE (&gvalue));
-				g_value_copy (&gvalue, &gvalue_copy);
+					cache_delete_value (tracker_class_get_name (*domain_index_classes), field_name, &gvalue_copy, multiple_values,
+					                    tracker_property_get_fulltext_indexed (property),
+					                    tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_DATETIME);
 
-				cache_delete_value (tracker_class_get_name (domain_index_class), field_name, &gvalue_copy, multiple_values,
-				                    tracker_property_get_fulltext_indexed (property),
-				                    tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_DATETIME);
+					domain_index_classes++;
+				}
 			}
 		}
 
@@ -1639,19 +1661,23 @@ cache_delete_resource_type (TrackerClass *class,
 
 
 			if (!multiple_values) {
-				TrackerClass *domain_index_class;
+				TrackerClass **domain_index_classes;
 
-				domain_index_class = tracker_property_get_domain_index (prop);
+				domain_index_classes = tracker_property_get_domain_indexes (prop);
 
-				if (domain_index_class) {
-					GValue gvalue_copy = { 0 };
+				if (resource_in_domain_index (domain_index_classes)) {
+					while (*domain_index_classes) {
+						GValue gvalue_copy = { 0 };
 
-					g_value_init (&gvalue_copy, G_VALUE_TYPE (&gvalue));
-					g_value_copy (&gvalue, &gvalue_copy);
+						g_value_init (&gvalue_copy, G_VALUE_TYPE (&gvalue));
+						g_value_copy (&gvalue, &gvalue_copy);
 
-					cache_delete_value (tracker_class_get_name (domain_index_class), field_name, &gvalue_copy, multiple_values,
-					                    tracker_property_get_fulltext_indexed (prop),
-					                    tracker_property_get_data_type (prop) == TRACKER_PROPERTY_TYPE_DATETIME);
+						cache_delete_value (tracker_class_get_name (*domain_index_classes), field_name, &gvalue_copy, multiple_values,
+						                    tracker_property_get_fulltext_indexed (prop),
+						                    tracker_property_get_data_type (prop) == TRACKER_PROPERTY_TYPE_DATETIME);
+
+						domain_index_classes++;
+					}
 				}
 			}
 
diff --git a/src/libtracker-data/tracker-property.c b/src/libtracker-data/tracker-property.c
index 77ca25c..95be01a 100644
--- a/src/libtracker-data/tracker-property.c
+++ b/src/libtracker-data/tracker-property.c
@@ -66,6 +66,7 @@ struct _TrackerPropertyPrivate {
 	gboolean       is_new_domain_index;
 
 	GArray        *super_properties;
+	GArray        *domain_indexes;
 };
 
 static void property_finalize     (GObject      *object);
@@ -135,6 +136,7 @@ tracker_property_init (TrackerProperty *property)
 	priv->transient = FALSE;
 	priv->multiple_values = TRUE;
 	priv->super_properties = g_array_new (TRUE, TRUE, sizeof (TrackerProperty *));
+	priv->domain_indexes = g_array_new (TRUE, TRUE, sizeof (TrackerClass *));
 
 	/* Make GET_PRIV working */
 	property->priv = priv;
@@ -164,6 +166,7 @@ property_finalize (GObject *object)
 	}
 
 	g_array_free (priv->super_properties, TRUE);
+	g_array_free (priv->domain_indexes, TRUE);
 
 	g_free (priv->default_value);
 
@@ -273,8 +276,8 @@ tracker_property_get_domain (TrackerProperty *property)
 	return priv->domain;
 }
 
-TrackerClass *
-tracker_property_get_domain_index (TrackerProperty *property)
+TrackerClass **
+tracker_property_get_domain_indexes (TrackerProperty *property)
 {
 	TrackerPropertyPrivate *priv;
 
@@ -285,7 +288,7 @@ tracker_property_get_domain_index (TrackerProperty *property)
 
 	priv = GET_PRIV (property);
 
-	return priv->domain_index;
+	return priv->domain_indexes->data;
 }
 
 TrackerClass *
@@ -559,23 +562,17 @@ tracker_property_set_domain (TrackerProperty *property,
 }
 
 void
-tracker_property_set_domain_index (TrackerProperty *property,
+tracker_property_add_domain_index (TrackerProperty *property,
                                    TrackerClass    *value)
 {
 	TrackerPropertyPrivate *priv;
 
 	g_return_if_fail (TRACKER_IS_PROPERTY (property));
+	g_return_if_fail (TRACKER_IS_PROPERTY (value));
 
 	priv = GET_PRIV (property);
 
-	if (priv->domain_index) {
-		g_object_unref (priv->domain_index);
-		priv->domain_index = NULL;
-	}
-
-	if (value) {
-		priv->domain_index = g_object_ref (value);
-	}
+	g_array_append_val (priv->domain_indexes, value);
 }
 
 void
diff --git a/src/libtracker-data/tracker-property.h b/src/libtracker-data/tracker-property.h
index 7b7d70c..fd5aedf 100644
--- a/src/libtracker-data/tracker-property.h
+++ b/src/libtracker-data/tracker-property.h
@@ -80,7 +80,7 @@ const gchar *       tracker_property_get_table_name          (TrackerProperty
 TrackerPropertyType tracker_property_get_data_type           (TrackerProperty      *property);
 TrackerClass *      tracker_property_get_domain              (TrackerProperty      *property);
 TrackerClass *      tracker_property_get_range               (TrackerProperty      *property);
-TrackerClass *      tracker_property_get_domain_index        (TrackerProperty      *property);
+TrackerClass **     tracker_property_get_domain_indexes      (TrackerProperty      *property);
 gint                tracker_property_get_weight              (TrackerProperty      *property);
 gint                tracker_property_get_id                  (TrackerProperty      *property);
 gboolean            tracker_property_get_indexed             (TrackerProperty      *property);
@@ -102,7 +102,7 @@ void                tracker_property_set_uri                 (TrackerProperty
                                                               const gchar          *value);
 void                tracker_property_set_domain              (TrackerProperty      *property,
                                                               TrackerClass         *value);
-void                tracker_property_set_domain_index        (TrackerProperty      *property,
+void                tracker_property_add_domain_index        (TrackerProperty      *property,
                                                               TrackerClass         *value);
 void                tracker_property_set_range               (TrackerProperty      *property,
                                                               TrackerClass         *range);



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