[tracker/rss-enclosures] libtracker-data: Support disabling FTS



commit 2fb3b341983ba527dcef39b836e87a797b7dc7f8
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Tue Jun 15 14:09:10 2010 +0200

    libtracker-data: Support disabling FTS

 src/libtracker-data/tracker-data-manager.c |   24 ++++--
 src/libtracker-data/tracker-data-update.c  |  115 +++++++++++++++++-----------
 2 files changed, 87 insertions(+), 52 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 359d253..e931808 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -32,7 +32,9 @@
 
 #include <libtracker-common/tracker-common.h>
 
+#if HAVE_TRACKER_FTS
 #include <libtracker-fts/tracker-fts.h>
+#endif
 
 #include <libtracker-db/tracker-db-interface-sqlite.h>
 #include <libtracker-db/tracker-db-manager.h>
@@ -741,7 +743,7 @@ tracker_data_ontology_process_changes (GPtrArray *seen_classes,
 	gint i;
 
 	/* This updates property-property changes and marks classes for necessity
-	 * of having their tables recreated later. There's support for 
+	 * of having their tables recreated later. There's support for
 	 * tracker:notify, tracker:writeback and tracker:indexed */
 
 	if (seen_classes) {
@@ -833,7 +835,7 @@ tracker_data_ontology_process_changes (GPtrArray *seen_classes,
 			}
 
 			if (update_property_value ("rdfs:range", subject, RDFS_PREFIX "range",
-			                           tracker_class_get_uri (tracker_property_get_range (property)), 
+			                           tracker_class_get_uri (tracker_property_get_range (property)),
 			                           allowed_range_conversions,
 			                           NULL, property)) {
 				TrackerClass *class;
@@ -1913,9 +1915,9 @@ create_decomposed_metadata_tables (TrackerDBInterface *iface,
 
 				if (in_update) {
 					g_debug ("%sAltering database for class '%s' property '%s': single value (%s)",
-					         in_alter ? "" : "  ", 
-					         service_name, 
-					         field_name, 
+					         in_alter ? "" : "  ",
+					         service_name,
+					         field_name,
 					         in_alter ? "alter" : "create");
 				}
 
@@ -2110,7 +2112,7 @@ create_decomposed_transient_metadata_tables (TrackerDBInterface *iface)
 	}
 }
 
-void 
+void
 tracker_data_ontology_import_finished (void)
 {
 	TrackerClass **classes;
@@ -2277,7 +2279,9 @@ tracker_data_manager_init (TrackerDBManagerFlags  flags,
 		return FALSE;
 	}
 
+#if HAVE_TRACKER_FTS
 	tracker_fts_set_map_function (tracker_ontologies_get_uri_by_id);
+#endif
 
 	if (first_time != NULL) {
 		*first_time = is_first_time_index;
@@ -2319,14 +2323,17 @@ tracker_data_manager_init (TrackerDBManagerFlags  flags,
 
 		/* Read first ontology and commit it into the DB */
 		tracker_data_begin_db_transaction_for_replay (tracker_db_journal_reader_get_time ());
+
+		/* This is a no-op when FTS is disabled */
 		tracker_db_interface_sqlite_fts_init (iface, TRUE);
+
 		tracker_data_ontology_import_into_db (FALSE);
 		tracker_data_commit_db_transaction ();
 		tracker_db_journal_reader_shutdown ();
 
 		/* Start replay. Ontology changes might happen during replay of the journal. */
 
-		tracker_data_replay_journal (classes, properties, id_uri_map, 
+		tracker_data_replay_journal (classes, properties, id_uri_map,
 		                             busy_callback, busy_user_data, busy_status);
 
 		in_journal_replay = FALSE;
@@ -2375,7 +2382,9 @@ tracker_data_manager_init (TrackerDBManagerFlags  flags,
 		/* Not an ontology transaction: this is the first ontology */
 		tracker_db_journal_start_transaction (time (NULL));
 
+		/* This is a no-op when FTS is disabled */
 		tracker_db_interface_sqlite_fts_init (iface, TRUE);
+
 		tracker_data_ontology_import_into_db (FALSE);
 
 		/* store ontology in database */
@@ -2413,6 +2422,7 @@ tracker_data_manager_init (TrackerDBManagerFlags  flags,
 		create_decomposed_transient_metadata_tables (iface);
 		check_ontology = TRUE;
 
+		/* This is a no-op when FTS is disabled */
 		tracker_db_interface_sqlite_fts_init (iface, FALSE);
 	}
 
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index a8ab034..789f190 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -29,7 +29,9 @@
 #include <libtracker-common/tracker-file-utils.h>
 #include <libtracker-common/tracker-ontologies.h>
 
+#if HAVE_TRACKER_FTS
 #include <libtracker-fts/tracker-fts.h>
+#endif
 
 #include <libtracker-db/tracker-db-manager.h>
 #include <libtracker-db/tracker-db-dbus.h>
@@ -70,30 +72,39 @@ struct _TrackerDataUpdateBuffer {
 	GHashTable *resources_by_id;
 
 	/* the following two fields are valid per sqlite transaction, not just for same subject */
-	gboolean fts_ever_updated;
 	/* TrackerClass -> integer */
 	GHashTable *class_counts;
+
+#if HAVE_TRACKER_FTS
+	gboolean fts_ever_updated;
+#endif
 };
 
 struct _TrackerDataUpdateBufferResource {
 	const gchar *subject;
 	gint id;
 	gboolean create;
-	gboolean fts_updated;
 	/* TrackerProperty -> GValueArray */
 	GHashTable *predicates;
 	/* string -> TrackerDataUpdateBufferTable */
 	GHashTable *tables;
 	/* TrackerClass */
 	GPtrArray *types;
+
+#if HAVE_TRACKER_FTS
+	gboolean fts_updated;
+#endif
 };
 
 struct _TrackerDataUpdateBufferProperty {
 	const gchar *name;
 	GValue value;
 	gint graph;
-	gboolean fts : 1;
 	gboolean date_time : 1;
+
+#if HAVE_TRACKER_FTS
+	gboolean fts : 1;
+#endif
 };
 
 struct _TrackerDataUpdateBufferTable {
@@ -482,7 +493,9 @@ cache_insert_value (const gchar            *table_name,
 
 	property.value = *value;
 	property.graph = graph;
+#if TRACKER_HAVE_FTS
 	property.fts = fts;
+#endif
 	property.date_time = date_time;
 
 	table = cache_ensure_table (table_name, multiple_values);
@@ -513,7 +526,9 @@ cache_delete_value (const gchar            *table_name,
 	property.name = field_name;
 	property.value = *value;
 	property.graph = 0;
+#if TRACKER_HAVE_FTS
 	property.fts = fts;
+#endif
 	property.date_time = date_time;
 
 	table = cache_ensure_table (table_name, multiple_values);
@@ -639,7 +654,7 @@ tracker_data_resource_buffer_flush (GError **error)
 	TrackerDataUpdateBufferProperty *property;
 	GHashTableIter                  iter;
 	const gchar                    *table_name;
-	GString                        *sql, *fts;
+	GString                        *sql;
 	gint                            i, param;
 	GError                         *actual_error = NULL;
 
@@ -834,6 +849,7 @@ tracker_data_resource_buffer_flush (GError **error)
 		}
 	}
 
+#if HAVE_TRACKER_FTS
 	if (resource_buffer->fts_updated) {
 		TrackerProperty *prop;
 		GValueArray *values;
@@ -843,6 +859,8 @@ tracker_data_resource_buffer_flush (GError **error)
 		g_hash_table_iter_init (&iter, resource_buffer->predicates);
 		while (g_hash_table_iter_next (&iter, (gpointer*) &prop, (gpointer*) &values)) {
 			if (tracker_property_get_fulltext_indexed (prop)) {
+				GString *fts;
+
 				fts = g_string_new ("");
 				for (i = 0; i < values->n_values; i++) {
 					g_string_append (fts, g_value_get_string (g_value_array_get_nth (values, i)));
@@ -855,6 +873,7 @@ tracker_data_resource_buffer_flush (GError **error)
 			}
 		}
 	}
+#endif
 }
 
 static void resource_buffer_free (TrackerDataUpdateBufferResource *resource)
@@ -918,8 +937,10 @@ tracker_data_update_buffer_clear (void)
 	g_hash_table_remove_all (update_buffer.resources_by_id);
 	resource_buffer = NULL;
 
+#if HAVE_TRACKER_FTS
 	tracker_fts_update_rollback ();
 	update_buffer.fts_ever_updated = FALSE;
+#endif
 
 	if (update_buffer.class_counts) {
 		/* revert class count changes */
@@ -1220,12 +1241,8 @@ static GValueArray *
 get_old_property_values (TrackerProperty  *property,
                          GError          **error)
 {
-	gboolean            fts;
-	TrackerProperty   **properties, *prop;
 	GValueArray        *old_values;
 
-	fts = tracker_property_get_fulltext_indexed (property);
-
 	/* read existing property values */
 	old_values = g_hash_table_lookup (resource_buffer->predicates, property);
 	if (old_values == NULL) {
@@ -1238,44 +1255,51 @@ get_old_property_values (TrackerProperty  *property,
 			return NULL;
 		}
 
-		if (fts && !resource_buffer->fts_updated && !resource_buffer->create) {
-			guint i, n_props;
+#if HAVE_TRACKER_FTS
+		if (tracker_property_get_fulltext_indexed (property)) {
+			if (!resource_buffer->fts_updated && !resource_buffer->create) {
+				guint i, n_props;
+				TrackerProperty   **properties, *prop;
 
-			/* first fulltext indexed property to be modified
-			 * retrieve values of all fulltext indexed properties
-			 */
-			tracker_fts_update_init (resource_buffer->id);
+				/* first fulltext indexed property to be modified
+				 * retrieve values of all fulltext indexed properties
+				 */
+				tracker_fts_update_init (resource_buffer->id);
 
-			properties = tracker_ontologies_get_properties (&n_props);
+				properties = tracker_ontologies_get_properties (&n_props);
 
-			for (i = 0; i < n_props; i++) {
-				prop = properties[i];
+				for (i = 0; i < n_props; i++) {
+					prop = properties[i];
 
-				if (tracker_property_get_fulltext_indexed (prop)
-				    && check_property_domain (prop)) {
-					gint i;
+					if (tracker_property_get_fulltext_indexed (prop)
+					    && check_property_domain (prop)) {
+						gint i;
 
-					old_values = get_property_values (prop);
+						old_values = get_property_values (prop);
 
-					/* delete old fts entries */
-					for (i = 0; i < old_values->n_values; i++) {
-						tracker_fts_update_text (resource_buffer->id, -1,
-						                         g_value_get_string (g_value_array_get_nth (old_values, i)),
-									 !tracker_property_get_fulltext_no_limit (prop));
+						/* delete old fts entries */
+						for (i = 0; i < old_values->n_values; i++) {
+							tracker_fts_update_text (resource_buffer->id, -1,
+							                         g_value_get_string (g_value_array_get_nth (old_values, i)),
+							                         !tracker_property_get_fulltext_no_limit (prop));
+						}
 					}
 				}
-			}
 
-			update_buffer.fts_ever_updated = TRUE;
+				update_buffer.fts_ever_updated = TRUE;
 
-			old_values = g_hash_table_lookup (resource_buffer->predicates, property);
-		} else {
-			old_values = get_property_values (property);
-		}
+				old_values = g_hash_table_lookup (resource_buffer->predicates, property);
+			} else {
+				old_values = get_property_values (property);
+			}
 
-		if (fts) {
 			resource_buffer->fts_updated = TRUE;
+		} else {
+			old_values = get_property_values (property);
 		}
+#else
+		old_values = get_property_values (property);
+#endif
 	}
 
 	return old_values;
@@ -1332,7 +1356,7 @@ cache_set_metadata_decomposed (TrackerProperty  *property,
                                gint              graph_id,
                                GError          **error)
 {
-	gboolean            multiple_values, fts;
+	gboolean            multiple_values;
 	const gchar        *table_name;
 	const gchar        *field_name;
 	TrackerProperty   **super_properties;
@@ -1357,8 +1381,6 @@ cache_set_metadata_decomposed (TrackerProperty  *property,
 	table_name = tracker_property_get_table_name (property);
 	field_name = tracker_property_get_name (property);
 
-	fts = tracker_property_get_fulltext_indexed (property);
-
 	/* read existing property values */
 	old_values = get_old_property_values (property, &new_error);
 	if (new_error) {
@@ -1414,7 +1436,8 @@ cache_set_metadata_decomposed (TrackerProperty  *property,
 	} else {
 		cache_insert_value (table_name, field_name, &gvalue,
 		                    graph != NULL ? ensure_resource_id (graph, NULL) : graph_id,
-		                    multiple_values, fts,
+		                    multiple_values,
+		                    tracker_property_get_fulltext_indexed (property),
 		                    tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_DATETIME);
 
 		change = TRUE;
@@ -1429,7 +1452,7 @@ delete_metadata_decomposed (TrackerProperty  *property,
                             gint              value_id,
                             GError          **error)
 {
-	gboolean            multiple_values, fts;
+	gboolean            multiple_values;
 	const gchar        *table_name;
 	const gchar        *field_name;
 	TrackerProperty   **super_properties;
@@ -1442,8 +1465,6 @@ delete_metadata_decomposed (TrackerProperty  *property,
 	table_name = tracker_property_get_table_name (property);
 	field_name = tracker_property_get_name (property);
 
-	fts = tracker_property_get_fulltext_indexed (property);
-
 	/* read existing property values */
 	old_values = get_old_property_values (property, &new_error);
 	if (new_error) {
@@ -1466,7 +1487,8 @@ delete_metadata_decomposed (TrackerProperty  *property,
 		/* value not found */
 		g_value_unset (&gvalue);
 	} else {
-		cache_delete_value (table_name, field_name, &gvalue, multiple_values, fts,
+		cache_delete_value (table_name, field_name, &gvalue, multiple_values,
+		                    tracker_property_get_fulltext_indexed (property),
 		                    tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_DATETIME);
 
 		change = TRUE;
@@ -1547,7 +1569,7 @@ cache_delete_resource_type (TrackerClass *class,
 	properties = tracker_ontologies_get_properties (&n_props);
 
 	for (p = 0; p < n_props; p++) {
-		gboolean            multiple_values, fts;
+		gboolean            multiple_values;
 		const gchar        *table_name;
 		const gchar        *field_name;
 		GValueArray        *old_values;
@@ -1563,8 +1585,6 @@ cache_delete_resource_type (TrackerClass *class,
 		table_name = tracker_property_get_table_name (prop);
 		field_name = tracker_property_get_name (prop);
 
-		fts = tracker_property_get_fulltext_indexed (prop);
-
 		old_values = get_old_property_values (prop, NULL);
 
 		for (i = old_values->n_values - 1; i >= 0 ; i--) {
@@ -1576,7 +1596,8 @@ cache_delete_resource_type (TrackerClass *class,
 			g_value_copy (old_gvalue, &gvalue);
 
 			value_set_remove_value (old_values, &gvalue);
-			cache_delete_value (table_name, field_name, &gvalue, multiple_values, fts,
+			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);
 		}
 	}
@@ -1638,7 +1659,9 @@ resource_buffer_switch (const gchar *graph,
 		} else {
 			resource_buffer->id = ensure_resource_id (resource_buffer->subject, &resource_buffer->create);
 		}
+#if HAVE_TRACKER_FTS
 		resource_buffer->fts_updated = FALSE;
+#endif
 		if (resource_buffer->create) {
 			resource_buffer->types = g_ptr_array_new ();
 		} else {
@@ -2063,10 +2086,12 @@ tracker_data_commit_db_transaction (void)
 
 	tracker_data_update_buffer_flush (NULL);
 
+#if HAVE_TRACKER_FTS
 	if (update_buffer.fts_ever_updated) {
 		tracker_fts_update_commit ();
 		update_buffer.fts_ever_updated = FALSE;
 	}
+#endif
 
 	if (update_buffer.class_counts) {
 		/* successful transaction, no need to rollback class counts,



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