[tracker] libtracker-data: Also write to the domain class' table in case of domain specific index



commit 7400cf15f2ba57a0b733815eb3647ff4be9335f0
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Jul 1 15:18:03 2010 +0200

    libtracker-data: Also write to the domain class' table in case of domain specific index

 src/libtracker-data/tracker-data-manager.c |    3 +
 src/libtracker-data/tracker-data-update.c  |   58 +++++++++++++++++++++++++++-
 src/libtracker-data/tracker-property.c     |   36 +++++++++++++++++
 src/libtracker-data/tracker-property.h     |    3 +
 4 files changed, 99 insertions(+), 1 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index c58a697..1f2ff08 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -560,6 +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);
 		}
 
 	} else if (g_strcmp0 (predicate, TRACKER_PREFIX "writeback") == 0) {
@@ -1304,6 +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);
 		}
 
 		g_object_unref (cursor);
@@ -1638,6 +1640,7 @@ 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 e2d5d82..f33a4e8 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -1369,7 +1369,7 @@ cache_set_metadata_decomposed (TrackerProperty  *property,
 	super_properties = tracker_property_get_super_properties (property);
 	while (*super_properties) {
 		change |= cache_set_metadata_decomposed (*super_properties, value, value_id,
-		                               graph, graph_id, &new_error);
+		                                         graph, graph_id, &new_error);
 		if (new_error) {
 			g_propagate_error (error, new_error);
 			return FALSE;
@@ -1434,12 +1434,32 @@ cache_set_metadata_decomposed (TrackerProperty  *property,
 		g_value_unset (&gvalue);
 
 	} else {
+
 		cache_insert_value (table_name, field_name, &gvalue,
 		                    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);
 
+		if (!multiple_values) {
+			TrackerClass *domain_index_class;
+
+			domain_index_class = tracker_property_get_domain_index (property);
+
+			if (domain_index_class) {
+				GValue gvalue_copy = { 0 };
+
+				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);
+			}
+		}
+
 		change = TRUE;
 	}
 
@@ -1491,6 +1511,23 @@ delete_metadata_decomposed (TrackerProperty  *property,
 		                    tracker_property_get_fulltext_indexed (property),
 		                    tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_DATETIME);
 
+		if (!multiple_values) {
+			TrackerClass *domain_index_class;
+
+			domain_index_class = tracker_property_get_domain_index (property);
+
+			if (domain_index_class) {
+				GValue gvalue_copy = { 0 };
+
+				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 (property),
+				                    tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_DATETIME);
+			}
+		}
+
 		change = TRUE;
 	}
 
@@ -1599,6 +1636,25 @@ cache_delete_resource_type (TrackerClass *class,
 			cache_delete_value (table_name, field_name, &gvalue, multiple_values,
 			                    tracker_property_get_fulltext_indexed (prop),
 			                    tracker_property_get_data_type (prop) == TRACKER_PROPERTY_TYPE_DATETIME);
+
+
+			if (!multiple_values) {
+				TrackerClass *domain_index_class;
+
+				domain_index_class = tracker_property_get_domain_index (prop);
+
+				if (domain_index_class) {
+					GValue gvalue_copy = { 0 };
+
+					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);
+				}
+			}
+
 		}
 	}
 
diff --git a/src/libtracker-data/tracker-property.c b/src/libtracker-data/tracker-property.c
index 72e3dd2..77ca25c 100644
--- a/src/libtracker-data/tracker-property.c
+++ b/src/libtracker-data/tracker-property.c
@@ -47,6 +47,7 @@ struct _TrackerPropertyPrivate {
 
 	TrackerPropertyType  data_type;
 	TrackerClass   *domain;
+	TrackerClass   *domain_index;
 	TrackerClass   *range;
 	gint           weight;
 	gint           id;
@@ -273,6 +274,21 @@ tracker_property_get_domain (TrackerProperty *property)
 }
 
 TrackerClass *
+tracker_property_get_domain_index (TrackerProperty *property)
+{
+	TrackerPropertyPrivate *priv;
+
+	/* Removed for performance:
+	 g_return_val_if_fail (TRACKER_IS_PROPERTY (property), NULL); */
+
+	g_return_val_if_fail (property != NULL, NULL);
+
+	priv = GET_PRIV (property);
+
+	return priv->domain_index;
+}
+
+TrackerClass *
 tracker_property_get_range (TrackerProperty *property)
 {
 	TrackerPropertyPrivate *priv;
@@ -543,6 +559,26 @@ tracker_property_set_domain (TrackerProperty *property,
 }
 
 void
+tracker_property_set_domain_index (TrackerProperty *property,
+                                   TrackerClass    *value)
+{
+	TrackerPropertyPrivate *priv;
+
+	g_return_if_fail (TRACKER_IS_PROPERTY (property));
+
+	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);
+	}
+}
+
+void
 tracker_property_set_secondary_index (TrackerProperty *property,
                                       TrackerProperty *value)
 {
diff --git a/src/libtracker-data/tracker-property.h b/src/libtracker-data/tracker-property.h
index d9c9c01..7b7d70c 100644
--- a/src/libtracker-data/tracker-property.h
+++ b/src/libtracker-data/tracker-property.h
@@ -80,6 +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);
 gint                tracker_property_get_weight              (TrackerProperty      *property);
 gint                tracker_property_get_id                  (TrackerProperty      *property);
 gboolean            tracker_property_get_indexed             (TrackerProperty      *property);
@@ -101,6 +102,8 @@ 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,
+                                                              TrackerClass         *value);
 void                tracker_property_set_range               (TrackerProperty      *property,
                                                               TrackerClass         *range);
 void                tracker_property_set_weight              (TrackerProperty      *property,



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