[tracker/wip/carlosg/update-perf: 10/61] libtracker-sparql: Simplify FTS text insertion




commit a6ff7801c172df8389c0a42637246b1a05a963ec
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu May 19 12:21:59 2022 +0200

    libtracker-sparql: Simplify FTS text insertion
    
    Pull the current values for FTS properties from the supporting view, instead
    of passing them explicitly. This makes FTS insertion and deletion pretty much
    1:1 in how text content is handled.

 src/libtracker-sparql/core/tracker-data-update.c   | 25 +++-----------
 .../core/tracker-db-interface-sqlite.c             | 40 ++++++++++------------
 .../core/tracker-db-interface-sqlite.h             |  3 +-
 3 files changed, 25 insertions(+), 43 deletions(-)
---
diff --git a/src/libtracker-sparql/core/tracker-data-update.c 
b/src/libtracker-sparql/core/tracker-data-update.c
index 4890224c2..ea25a862c 100644
--- a/src/libtracker-sparql/core/tracker-data-update.c
+++ b/src/libtracker-sparql/core/tracker-data-update.c
@@ -1057,42 +1057,27 @@ tracker_data_resource_buffer_flush (TrackerData                      *data,
        if (resource->fts_updated) {
                TrackerProperty *prop;
                GArray *values;
-               GPtrArray *properties, *text;
+               GPtrArray *properties;
 
-               properties = text = NULL;
+               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)) {
-                               GString *fts;
-
-                               fts = g_string_new ("");
-                               for (i = 0; i < values->len; i++) {
-                                       GValue *v = &g_array_index (values, GValue, i);
-                                       g_string_append (fts, g_value_get_string (v));
-                                       g_string_append_c (fts, ' ');
-                               }
-
-                               if (!properties && !text) {
+                               if (!properties)
                                        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) {
+               if (properties) {
                        g_ptr_array_add (properties, NULL);
-                       g_ptr_array_add (text, NULL);
 
                        tracker_db_interface_sqlite_fts_update_text (iface,
                                                                     database,
                                                                     resource->id,
-                                                                    (const gchar **) properties->pdata,
-                                                                    (const gchar **) text->pdata);
+                                                                    (const gchar **) properties->pdata);
                        g_ptr_array_free (properties, TRUE);
-                       g_ptr_array_free (text, TRUE);
                }
        }
 }
diff --git a/src/libtracker-sparql/core/tracker-db-interface-sqlite.c 
b/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
index 54163d615..04c9a79b8 100644
--- a/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
+++ b/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
@@ -2339,38 +2339,40 @@ tracker_db_interface_sqlite_fts_create_update_query (TrackerDBInterface  *db_int
                                                      const gchar         *database,
                                                      const gchar        **properties)
 {
-       GString *insert_str, *values_str;
-       gint i;
+        GString *props_str;
+        gchar *query;
+        gint i;
 
-       insert_str = g_string_new (NULL);
-       g_string_append_printf (insert_str, "INSERT INTO \"%s\".fts5 (", database);
-       values_str = g_string_new (NULL);
+        props_str = g_string_new (NULL);
 
-       g_string_append (insert_str, "rowid");
-       g_string_append (values_str, "?");
+        for (i = 0; properties[i] != NULL; i++) {
+               if (i != 0)
+                       g_string_append_c (props_str, ',');
 
-       for (i = 0; properties[i] != NULL; i++) {
-               g_string_append_printf (insert_str, ",\"%s\"", properties[i]);
-               g_string_append (values_str, ",?");
-       }
+                g_string_append_printf (props_str, "\"%s\"", properties[i]);
+        }
 
-       g_string_append_printf (insert_str, ") VALUES (%s)", values_str->str);
-       g_string_free (values_str, TRUE);
+        query = g_strdup_printf ("INSERT INTO \"%s\".fts5 (ROWID, %s) "
+                                 "SELECT ROWID, %s FROM \"%s\".fts_view WHERE ROWID = ? AND COALESCE(%s, 
NULL) IS NOT NULL",
+                                 database,
+                                 props_str->str,
+                                 props_str->str,
+                                 database,
+                                 props_str->str);
+        g_string_free (props_str, TRUE);
 
-       return g_string_free (insert_str, FALSE);
+        return query;
 }
 
 gboolean
 tracker_db_interface_sqlite_fts_update_text (TrackerDBInterface  *db_interface,
                                              const gchar         *database,
                                              int                  id,
-                                             const gchar        **properties,
-                                             const gchar        **text)
+                                             const gchar        **properties)
 {
        TrackerDBStatement *stmt;
        GError *error = NULL;
        gchar *query;
-       gint i;
 
        query = tracker_db_interface_sqlite_fts_create_update_query (db_interface,
                                                                     database,
@@ -2391,10 +2393,6 @@ tracker_db_interface_sqlite_fts_update_text (TrackerDBInterface  *db_interface,
         }
 
         tracker_db_statement_bind_int (stmt, 0, id);
-        for (i = 0; text[i] != NULL; i++) {
-               tracker_db_statement_bind_text (stmt, i + 1, 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 c8a5b455e..1a892eace 100644
--- a/src/libtracker-sparql/core/tracker-db-interface-sqlite.h
+++ b/src/libtracker-sparql/core/tracker-db-interface-sqlite.h
@@ -70,8 +70,7 @@ gboolean            tracker_db_interface_sqlite_fts_alter_table        (TrackerD
 gboolean            tracker_db_interface_sqlite_fts_update_text        (TrackerDBInterface       
*db_interface,
                                                                         const gchar              *database,
                                                                        int                       id,
-                                                                        const gchar             **properties,
-                                                                        const gchar             **text);
+                                                                        const gchar             
**properties);
 
 gboolean            tracker_db_interface_sqlite_fts_delete_text        (TrackerDBInterface       *interface,
                                                                         const gchar              *database,


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