[tracker/wip/carlosg/update-perf: 7/61] libtracker-data: Shuffle FTS text deletion




commit 23e58f3559c4103af5478e6885f013417224f9f5
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Jan 18 14:03:42 2022 +0100

    libtracker-data: Shuffle FTS text deletion
    
    Move it to buffer_flush(), so it's paired together with FTS updates.
    This also makes get_old_property_values() not have side effects wrt
    FTS.

 src/libtracker-sparql/core/tracker-data-update.c   | 97 ++++++++++------------
 .../core/tracker-db-interface-sqlite.c             | 15 ++--
 2 files changed, 54 insertions(+), 58 deletions(-)
---
diff --git a/src/libtracker-sparql/core/tracker-data-update.c 
b/src/libtracker-sparql/core/tracker-data-update.c
index 47bff7cae..b5f6c660f 100644
--- a/src/libtracker-sparql/core/tracker-data-update.c
+++ b/src/libtracker-sparql/core/tracker-data-update.c
@@ -842,6 +842,34 @@ tracker_data_resource_buffer_flush (TrackerData                      *data,
        iface = tracker_data_manager_get_writable_db_interface (data->manager);
        database = resource->graph->graph ? resource->graph->graph : "main";
 
+       if (resource->fts_updated && !resource->create) {
+               TrackerProperty *prop;
+               GArray *values;
+               GPtrArray *properties;
+
+               properties = NULL;
+               g_hash_table_iter_init (&iter, resource->predicates);
+
+               while (g_hash_table_iter_next (&iter, (gpointer*) &prop, (gpointer*) &values)) {
+                       if (tracker_property_get_fulltext_indexed (prop)) {
+                               if (!properties)
+                                       properties = g_ptr_array_new ();
+
+                               g_ptr_array_add (properties, (gpointer) tracker_property_get_name (prop));
+                       }
+               }
+
+               if (properties) {
+                       g_ptr_array_add (properties, NULL);
+
+                       tracker_db_interface_sqlite_fts_delete_text (iface,
+                                                                    database,
+                                                                    resource->id,
+                                                                    (const gchar **) properties->pdata);
+                       g_ptr_array_free (properties, TRUE);
+               }
+       }
+
        g_hash_table_iter_init (&iter, resource->tables);
        while (g_hash_table_iter_next (&iter, (gpointer*) &table_name, (gpointer*) &table)) {
                if (table->multiple_values) {
@@ -1608,10 +1636,6 @@ get_old_property_values (TrackerData      *data,
                          GError          **error)
 {
        GArray *old_values;
-       const gchar *database;
-
-       database = data->resource_buffer->graph->graph ?
-               data->resource_buffer->graph->graph : "main";
 
        /* read existing property values */
        old_values = g_hash_table_lookup (data->resource_buffer->predicates, property);
@@ -1643,55 +1667,9 @@ get_old_property_values (TrackerData      *data,
                        }
                }
 
-               if (tracker_property_get_fulltext_indexed (property)) {
-                       TrackerDBInterface *iface;
-
-                       iface = tracker_data_manager_get_writable_db_interface (data->manager);
-
-                       if (!data->resource_buffer->fts_updated && !data->resource_buffer->create) {
-                               TrackerOntologies *ontologies;
-                               guint i, n_props;
-                               TrackerProperty   **properties, *prop;
-                               GPtrArray *fts_props;
-
-                               /* first fulltext indexed property to be modified
-                                * retrieve values of all fulltext indexed properties
-                                */
-                               ontologies = tracker_data_manager_get_ontologies (data->manager);
-                               properties = tracker_ontologies_get_properties (ontologies, &n_props);
-
-                               fts_props = g_ptr_array_new ();
-
-                               for (i = 0; i < n_props; i++) {
-                                       prop = properties[i];
-
-                                       if (tracker_property_get_fulltext_indexed (prop)
-                                           && check_property_domain (data, prop)) {
-                                               const gchar *property_name;
-
-                                               property_name = tracker_property_get_name (prop);
-                                               g_ptr_array_add (fts_props, (gpointer) property_name);
-                                       }
-                               }
-
-                               g_ptr_array_add (fts_props, NULL);
-
-                               tracker_db_interface_sqlite_fts_delete_text (iface,
-                                                                            database,
-                                                                            data->resource_buffer->id,
-                                                                            (const gchar **) 
fts_props->pdata);
-
-                               g_ptr_array_unref (fts_props);
-
-                               old_values = get_property_values (data, property, error);
-                               data->resource_buffer->fts_updated = TRUE;
-                       } else {
-                               old_values = get_property_values (data, property, error);
-                       }
-
-               } else {
-                       old_values = get_property_values (data, property, error);
-               }
+               data->resource_buffer->fts_updated |=
+                       tracker_property_get_fulltext_indexed (property);
+               old_values = get_property_values (data, property, error);
        }
 
        return old_values;
@@ -1947,6 +1925,9 @@ delete_metadata_decomposed (TrackerData      *data,
        table_name = tracker_property_get_table_name (property);
        field_name = tracker_property_get_name (property);
 
+       data->resource_buffer->fts_updated |=
+               tracker_property_get_fulltext_indexed (property);
+
        /* read existing property values */
        old_values = get_old_property_values (data, property, &new_error);
        if (new_error) {
@@ -2117,7 +2098,11 @@ cache_delete_resource_type_full (TrackerData   *data,
                table_name = tracker_property_get_table_name (prop);
                field_name = tracker_property_get_name (prop);
 
+               data->resource_buffer->fts_updated |=
+                       tracker_property_get_fulltext_indexed (prop);
+
                old_values = get_old_property_values (data, prop, error);
+
                if (!old_values)
                        return FALSE;
 
@@ -2674,6 +2659,9 @@ tracker_data_update_statement (TrackerData      *data,
                if (!resource_buffer_switch (data, graph, subject, error))
                        return;
 
+               data->resource_buffer->fts_updated |=
+                       tracker_property_get_fulltext_indexed (predicate);
+
                cache_delete_all_values (data,
                                         tracker_property_get_table_name (predicate),
                                         tracker_property_get_name (predicate));
@@ -2685,6 +2673,9 @@ tracker_data_update_statement (TrackerData      *data,
                if (!resource_buffer_switch (data, graph, subject, error))
                        return;
 
+               data->resource_buffer->fts_updated |=
+                       tracker_property_get_fulltext_indexed (predicate);
+
                if (!delete_single_valued (data, graph, subject, predicate,
                                           !tracker_property_get_multiple_values (predicate),
                                           error))
diff --git a/src/libtracker-sparql/core/tracker-db-interface-sqlite.c 
b/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
index 570e9afff..54163d615 100644
--- a/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
+++ b/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
@@ -2418,15 +2418,20 @@ tracker_db_interface_sqlite_fts_create_delete_query (TrackerDBInterface  *db_int
 
         props_str = g_string_new (NULL);
 
-        for (i = 0; properties[i] != NULL; i++)
-                g_string_append_printf (props_str, ",\"%s\"", properties[i]);
+        for (i = 0; properties[i] != NULL; i++) {
+               if (i != 0)
+                       g_string_append_c (props_str, ',');
 
-        query = g_strdup_printf ("INSERT INTO \"%s\".fts5 (fts5, ROWID %s) "
-                                 "SELECT 'delete', ROWID %s FROM \"%s\".fts_view WHERE ROWID = ?",
+                g_string_append_printf (props_str, "\"%s\"", properties[i]);
+        }
+
+        query = g_strdup_printf ("INSERT INTO \"%s\".fts5 (fts5, ROWID, %s) "
+                                 "SELECT 'delete', ROWID, %s FROM \"%s\".fts_view WHERE ROWID = ? AND 
COALESCE(%s, NULL) IS NOT NULL",
                                  database,
                                  props_str->str,
                                  props_str->str,
-                                 database);
+                                 database,
+                                 props_str->str);
         g_string_free (props_str, TRUE);
 
         return query;


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