summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2019-12-07 14:28:13 +0100
committerCarlos Garnacho <carlosg@gnome.org>2019-12-10 14:33:24 +0100
commit5c10b1aa3fefbd9fc150b3d662104d76eac6da30 (patch)
treec8f3e92c4816d333c6b882c7784da6bbe20ab0c0
parentd4a09db73fab92178a64ce5e06e8c6f70312673e (diff)
downloadtracker-5c10b1aa3fefbd9fc150b3d662104d76eac6da30.tar.gz
libtracker-data: Perform FTS deletes in a single query
External content FTS5 tables have trouble with partial column updates, possibly deeming the index corrupt afterwards. So perform deletes just like updates, in a manner that a row is updated all at once. As we were already doing the deletes for all FTS properties one by one before proceeding with the insertion of new values, this is slightly nicer in that we just make a single update now. Still quite a cumbersome peculiarity.
-rw-r--r--src/libtracker-data/tracker-data-update.c22
-rw-r--r--src/libtracker-data/tracker-db-interface-sqlite.c10
-rw-r--r--src/libtracker-data/tracker-db-interface-sqlite.h7
3 files changed, 25 insertions, 14 deletions
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index c5d2941fc..e2f46685e 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -1577,6 +1577,7 @@ get_old_property_values (TrackerData *data,
TrackerOntologies *ontologies;
guint i, n_props;
TrackerProperty **properties, *prop;
+ GPtrArray *fts_props, *fts_text;
/* first fulltext indexed property to be modified
* retrieve values of all fulltext indexed properties
@@ -1584,6 +1585,9 @@ get_old_property_values (TrackerData *data,
ontologies = tracker_data_manager_get_ontologies (data->manager);
properties = tracker_ontologies_get_properties (ontologies, &n_props);
+ fts_props = g_ptr_array_new ();
+ fts_text = g_ptr_array_new_with_free_func (g_free);
+
for (i = 0; i < n_props; i++) {
prop = properties[i];
@@ -1605,14 +1609,22 @@ get_old_property_values (TrackerData *data,
g_string_append (str, g_value_get_string (value));
}
- tracker_db_interface_sqlite_fts_delete_text (iface,
- data->resource_buffer->id,
- property_name,
- str->str);
- g_string_free (str, TRUE);
+ g_ptr_array_add (fts_props, (gpointer) property_name);
+ g_ptr_array_add (fts_text, g_string_free (str, FALSE));
}
}
+ g_ptr_array_add (fts_props, NULL);
+ g_ptr_array_add (fts_text, NULL);
+
+ tracker_db_interface_sqlite_fts_delete_text (iface,
+ data->resource_buffer->id,
+ (const gchar **) fts_props->pdata,
+ (const gchar **) fts_text->pdata);
+
+ g_ptr_array_unref (fts_props);
+ g_ptr_array_unref (fts_text);
+
data->update_buffer.fts_ever_updated = TRUE;
old_values = g_hash_table_lookup (data->resource_buffer->predicates, property);
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c b/src/libtracker-data/tracker-db-interface-sqlite.c
index 16d201d10..da88080ed 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -1824,13 +1824,13 @@ tracker_db_interface_sqlite_fts_update_text (TrackerDBInterface *db_interface,
gboolean
tracker_db_interface_sqlite_fts_delete_text (TrackerDBInterface *db_interface,
int rowid,
- const gchar *property,
- const gchar *old_text)
+ const gchar **properties,
+ const gchar **old_text)
{
TrackerDBStatement *stmt;
GError *error = NULL;
- const gchar *properties[] = { property, NULL };
gchar *query;
+ gint i;
query = tracker_db_interface_sqlite_fts_create_query (db_interface,
TRUE, properties);
@@ -1848,7 +1848,9 @@ tracker_db_interface_sqlite_fts_delete_text (TrackerDBInterface *db_interface,
}
tracker_db_statement_bind_int (stmt, 0, rowid);
- tracker_db_statement_bind_text (stmt, 1, old_text);
+ for (i = 0; old_text[i] != NULL; i++)
+ tracker_db_statement_bind_text (stmt, i + 1, old_text[i]);
+
tracker_db_statement_execute (stmt, &error);
g_object_unref (stmt);
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.h b/src/libtracker-data/tracker-db-interface-sqlite.h
index 4608bac94..b24ca1e4e 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.h
+++ b/src/libtracker-data/tracker-db-interface-sqlite.h
@@ -74,13 +74,10 @@ gboolean tracker_db_interface_sqlite_fts_update_text (TrackerD
gboolean tracker_db_interface_sqlite_fts_delete_text (TrackerDBInterface *interface,
int rowid,
- const gchar *property,
- const gchar *old_text);
+ const gchar **properties,
+ const gchar **old_text);
gboolean tracker_db_interface_sqlite_fts_delete_id (TrackerDBInterface *interface,
int rowid);
-void tracker_db_interface_sqlite_fts_update_commit (TrackerDBInterface *interface);
-void tracker_db_interface_sqlite_fts_update_rollback (TrackerDBInterface *interface);
-
void tracker_db_interface_sqlite_fts_rebuild_tokens (TrackerDBInterface *interface);
#endif