[tracker/wip/carlosg/fts-delete-2.3] libtracker-data: Perform FTS deletes in a single query



commit 5c10b1aa3fefbd9fc150b3d662104d76eac6da30
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Dec 7 14:28:13 2019 +0100

    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.

 src/libtracker-data/tracker-data-update.c         | 22 +++++++++++++++++-----
 src/libtracker-data/tracker-db-interface-sqlite.c | 10 ++++++----
 src/libtracker-data/tracker-db-interface-sqlite.h |  7 ++-----
 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


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