[tracker/wip/carlosg/update-perf: 6/61] libtracker-data: Drop requirement to pass text to FTS delete function




commit aabc1ae44de18befcd6b099561aa62c548c4755d
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Jan 18 12:07:36 2022 +0100

    libtracker-data: Drop requirement to pass text to FTS delete function
    
    Fetch the text to be deleted in place from the fts_view, since the
    query already happens at a time we are going to delete still present data.
    
    This avoids having to fetch FTS property contents, will be done more
    pervasively in future commits.

 src/libtracker-sparql/core/tracker-data-update.c   | 30 ++---------
 .../core/tracker-db-interface-sqlite.c             | 63 ++++++++++++----------
 .../core/tracker-db-interface-sqlite.h             |  3 +-
 3 files changed, 39 insertions(+), 57 deletions(-)
---
diff --git a/src/libtracker-sparql/core/tracker-data-update.c 
b/src/libtracker-sparql/core/tracker-data-update.c
index f4c857cd3..47bff7cae 100644
--- a/src/libtracker-sparql/core/tracker-data-update.c
+++ b/src/libtracker-sparql/core/tracker-data-update.c
@@ -1652,7 +1652,7 @@ get_old_property_values (TrackerData      *data,
                                TrackerOntologies *ontologies;
                                guint i, n_props;
                                TrackerProperty   **properties, *prop;
-                               GPtrArray *fts_props, *fts_text;
+                               GPtrArray *fts_props;
 
                                /* first fulltext indexed property to be modified
                                 * retrieve values of all fulltext indexed properties
@@ -1661,7 +1661,6 @@ get_old_property_values (TrackerData      *data,
                                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];
@@ -1669,45 +1668,22 @@ get_old_property_values (TrackerData      *data,
                                        if (tracker_property_get_fulltext_indexed (prop)
                                            && check_property_domain (data, prop)) {
                                                const gchar *property_name;
-                                               GString *str;
-                                               guint j;
-
-                                               old_values = get_property_values (data, prop, error);
-                                               if (!old_values) {
-                                                       g_ptr_array_unref (fts_props);
-                                                       g_ptr_array_unref (fts_text);
-                                                       return NULL;
-                                               }
 
                                                property_name = tracker_property_get_name (prop);
-                                               str = g_string_new (NULL);
-
-                                               /* delete old fts entries */
-                                               for (j = 0; j < old_values->len; j++) {
-                                                       GValue *value = &g_array_index (old_values, GValue, 
j);
-                                                       if (j != 0)
-                                                               g_string_append_c (str, ',');
-                                                       g_string_append (str, g_value_get_string (value));
-                                               }
-
                                                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,
                                                                             database,
                                                                             data->resource_buffer->id,
-                                                                            (const gchar **) 
fts_props->pdata,
-                                                                            (const gchar **) 
fts_text->pdata);
+                                                                            (const gchar **) 
fts_props->pdata);
 
                                g_ptr_array_unref (fts_props);
-                               g_ptr_array_unref (fts_text);
 
-                               old_values = g_hash_table_lookup (data->resource_buffer->predicates, 
property);
+                               old_values = get_property_values (data, property, error);
                                data->resource_buffer->fts_updated = TRUE;
                        } else {
                                old_values = get_property_values (data, property, error);
diff --git a/src/libtracker-sparql/core/tracker-db-interface-sqlite.c 
b/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
index 5a7ac18c7..570e9afff 100644
--- a/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
+++ b/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
@@ -2335,10 +2335,9 @@ tracker_db_interface_sqlite_fts_alter_table (TrackerDBInterface  *db_interface,
 }
 
 static gchar *
-tracker_db_interface_sqlite_fts_create_query (TrackerDBInterface  *db_interface,
-                                              const gchar         *database,
-                                              gboolean             delete,
-                                              const gchar        **properties)
+tracker_db_interface_sqlite_fts_create_update_query (TrackerDBInterface  *db_interface,
+                                                     const gchar         *database,
+                                                     const gchar        **properties)
 {
        GString *insert_str, *values_str;
        gint i;
@@ -2347,11 +2346,6 @@ tracker_db_interface_sqlite_fts_create_query (TrackerDBInterface  *db_interface,
        g_string_append_printf (insert_str, "INSERT INTO \"%s\".fts5 (", database);
        values_str = g_string_new (NULL);
 
-       if (delete) {
-               g_string_append (insert_str, "fts5,");
-               g_string_append (values_str, "'delete',");
-       }
-
        g_string_append (insert_str, "rowid");
        g_string_append (values_str, "?");
 
@@ -2378,9 +2372,9 @@ tracker_db_interface_sqlite_fts_update_text (TrackerDBInterface  *db_interface,
        gchar *query;
        gint i;
 
-       query = tracker_db_interface_sqlite_fts_create_query (db_interface,
-                                                             database,
-                                                             FALSE, properties);
+       query = tracker_db_interface_sqlite_fts_create_update_query (db_interface,
+                                                                    database,
+                                                                    properties);
        stmt = tracker_db_interface_create_statement (db_interface,
                                                      TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE,
                                                      &error,
@@ -2413,28 +2407,44 @@ tracker_db_interface_sqlite_fts_update_text (TrackerDBInterface  *db_interface,
         return TRUE;
 }
 
+static gchar *
+tracker_db_interface_sqlite_fts_create_delete_query (TrackerDBInterface  *db_interface,
+                                                     const gchar         *database,
+                                                     const gchar        **properties)
+{
+        GString *props_str;
+        gchar *query;
+        gint i;
+
+        props_str = g_string_new (NULL);
+
+        for (i = 0; properties[i] != NULL; i++)
+                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 = ?",
+                                 database,
+                                 props_str->str,
+                                 props_str->str,
+                                 database);
+        g_string_free (props_str, TRUE);
+
+        return query;
+}
+
 gboolean
 tracker_db_interface_sqlite_fts_delete_text (TrackerDBInterface  *db_interface,
                                              const gchar         *database,
                                              int                  rowid,
-                                             const gchar        **properties,
-                                             const gchar        **old_text)
+                                             const gchar        **properties)
 {
        TrackerDBStatement *stmt;
        GError *error = NULL;
        gchar *query;
-       gboolean has_text = FALSE;
-       gint i;
 
-       for (i = 0; old_text[i] != NULL; i++)
-               has_text |= old_text[i] && *old_text[i];
-
-       if (!has_text)
-               return TRUE;
-
-       query = tracker_db_interface_sqlite_fts_create_query (db_interface,
-                                                             database,
-                                                             TRUE, properties);
+       query = tracker_db_interface_sqlite_fts_create_delete_query (db_interface,
+                                                                    database,
+                                                                    properties);
        stmt = tracker_db_interface_create_statement (db_interface,
                                                      TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE,
                                                      &error,
@@ -2449,9 +2459,6 @@ tracker_db_interface_sqlite_fts_delete_text (TrackerDBInterface  *db_interface,
        }
 
        tracker_db_statement_bind_int (stmt, 0, rowid);
-       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-sparql/core/tracker-db-interface-sqlite.h 
b/src/libtracker-sparql/core/tracker-db-interface-sqlite.h
index 98fc4d7ee..c8a5b455e 100644
--- a/src/libtracker-sparql/core/tracker-db-interface-sqlite.h
+++ b/src/libtracker-sparql/core/tracker-db-interface-sqlite.h
@@ -76,8 +76,7 @@ gboolean            tracker_db_interface_sqlite_fts_update_text        (TrackerD
 gboolean            tracker_db_interface_sqlite_fts_delete_text        (TrackerDBInterface       *interface,
                                                                         const gchar              *database,
                                                                         int                       rowid,
-                                                                        const gchar             **properties,
-                                                                        const gchar             **old_text);
+                                                                        const gchar             
**properties);
 gboolean            tracker_db_interface_sqlite_fts_rebuild_tokens     (TrackerDBInterface       *interface,
                                                                         const gchar              *database,
                                                                         GError                  **error);


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