[tracker/fts4: 10/17] libtracker-data: Gather FTS changes to perform a single insert/update per ID
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/fts4: 10/17] libtracker-data: Gather FTS changes to perform a single insert/update per ID
- Date: Thu, 15 Dec 2011 18:23:24 +0000 (UTC)
commit e3e1bf80ec9dac8ec3358f91a995b39d83e92a5c
Author: Carlos Garnacho <carlos lanedo com>
Date: Tue Nov 8 11:58:34 2011 +0100
libtracker-data: Gather FTS changes to perform a single insert/update per ID
src/libtracker-data/tracker-data-update.c | 42 ++++++++------
src/libtracker-data/tracker-db-interface-sqlite.c | 60 ++++++++++++++-------
src/libtracker-data/tracker-db-interface-sqlite.h | 7 +--
3 files changed, 67 insertions(+), 42 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 269b848..f60d74d 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -962,7 +962,9 @@ tracker_data_resource_buffer_flush (GError **error)
TrackerProperty *prop;
GValueArray *values;
gboolean create = resource_buffer->create;
+ GPtrArray *properties, *text;
+ properties = text = NULL;
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)) {
@@ -973,20 +975,30 @@ tracker_data_resource_buffer_flush (GError **error)
g_string_append (fts, g_value_get_string (g_value_array_get_nth (values, i)));
g_string_append_c (fts, ' ');
}
- tracker_db_interface_sqlite_fts_update_text (iface,
- resource_buffer->id,
- tracker_property_get_name (prop),
- fts->str,
- !tracker_property_get_fulltext_no_limit (prop),
- create);
- g_string_free (fts, TRUE);
-
- /* Set that we ever updated FTS, so that tracker_db_interface_sqlite_fts_update_commit()
- * gets called */
- update_buffer.fts_ever_updated = TRUE;
- create = FALSE;
+
+ if (!properties && !text) {
+ properties = g_ptr_array_new ();
+ text = g_ptr_array_new_with_free_func ((GDestroyNotify) g_free);
+ }
+
+ g_ptr_array_add (properties, (gpointer) tracker_property_get_name (prop));
+ g_ptr_array_add (text, g_string_free (fts, FALSE));
}
}
+
+ if (properties && text) {
+ g_ptr_array_add (properties, NULL);
+ g_ptr_array_add (text, NULL);
+
+ tracker_db_interface_sqlite_fts_update_text (iface,
+ resource_buffer->id,
+ (gchar **) properties->pdata,
+ (gchar **) text->pdata,
+ create);
+ update_buffer.fts_ever_updated = TRUE;
+ g_ptr_array_free (properties, TRUE);
+ g_ptr_array_free (text, TRUE);
+ }
}
#endif
}
@@ -1048,12 +1060,6 @@ tracker_data_update_buffer_might_flush (GError **error)
static void
tracker_data_update_buffer_clear (void)
{
-#if HAVE_TRACKER_FTS
- TrackerDBInterface *iface;
-
- iface = tracker_db_manager_get_db_interface ();
-#endif
-
g_hash_table_remove_all (update_buffer.resources);
g_hash_table_remove_all (update_buffer.resources_by_id);
g_hash_table_remove_all (update_buffer.resource_cache);
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c b/src/libtracker-data/tracker-db-interface-sqlite.c
index 1bc3a38..c35b9ad 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -1011,32 +1011,48 @@ tracker_db_interface_sqlite_fts_alter_table (TrackerDBInterface *db_interface,
}
gboolean
-tracker_db_interface_sqlite_fts_update_text (TrackerDBInterface *db_interface,
- int id,
- const gchar *property,
- const char *text,
- gboolean limit_word_length,
- gboolean create)
+tracker_db_interface_sqlite_fts_update_text (TrackerDBInterface *db_interface,
+ int id,
+ const gchar **properties,
+ const char **text,
+ gboolean create)
{
TrackerDBStatement *stmt;
GError *error = NULL;
- gchar *query;
+ GString *query;
+ gint i;
if (create) {
- query = g_strdup_printf ("INSERT INTO fts (docid, \"%s\") "
- "VALUES (?, ?) ",
- property);
+ query = g_string_new ("INSERT INTO fts (docid");
+
+ for (i = 0; properties[i] != NULL; i++) {
+ g_string_append_printf (query, ", \"%s\"", properties[i]);
+ }
+
+ g_string_append (query, ") VALUES (?");
+
+ for (i = 0; properties[i] != NULL; i++) {
+ g_string_append (query, ", ?");
+ }
+
+ g_string_append_c (query, ')');
} else {
- query = g_strdup_printf ("UPDATE fts "
- "SET \"%s\" = ? "
- "WHERE docid = ? ",
- property);
+ query = g_string_new ("UPDATE fts SET ");
+
+ for (i = 0; properties[i] != NULL; i++) {
+ if (i != 0) {
+ g_string_append_c (query, ',');
+ }
+ g_string_append_printf (query, "\"%s\" = ?", properties[i]);
+ }
+
+ g_string_append (query, " WHERE docid = ?");
}
stmt = tracker_db_interface_create_statement (db_interface,
TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE,
- &error, query);
- g_free (query);
+ &error, query->str);
+ g_string_free (query, TRUE);
if (!stmt || error) {
if (error) {
@@ -1049,10 +1065,16 @@ tracker_db_interface_sqlite_fts_update_text (TrackerDBInterface *db_interface,
if (create) {
tracker_db_statement_bind_int (stmt, 0, id);
- tracker_db_statement_bind_text (stmt, 1, text);
+
+ for (i = 0; properties[i] != NULL; i++) {
+ tracker_db_statement_bind_text (stmt, i + 1, text[i]);
+ }
} else {
- tracker_db_statement_bind_text (stmt, 0, text);
- tracker_db_statement_bind_int (stmt, 1, id);
+ for (i = 0; properties[i] != NULL; i++) {
+ tracker_db_statement_bind_text (stmt, i, text[i]);
+ }
+
+ tracker_db_statement_bind_int (stmt, i, id);
}
tracker_db_statement_execute (stmt, &error);
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.h b/src/libtracker-data/tracker-db-interface-sqlite.h
index 6d825b1..f0e2d90 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.h
+++ b/src/libtracker-data/tracker-db-interface-sqlite.h
@@ -51,13 +51,10 @@ void tracker_db_interface_sqlite_wal_hook (TrackerD
void tracker_db_interface_sqlite_fts_alter_table (TrackerDBInterface *interface,
const gchar **added_columns,
const gchar **removed_columns);
-int tracker_db_interface_sqlite_fts_update_init (TrackerDBInterface *interface,
- int id);
int tracker_db_interface_sqlite_fts_update_text (TrackerDBInterface *interface,
int id,
- const gchar *property,
- const char *text,
- gboolean limit_word_length,
+ const gchar **properties,
+ const char **text,
gboolean create);
gboolean tracker_db_interface_sqlite_fts_delete_text (TrackerDBInterface *db_interface,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]