[tracker/wip/carlosg/update-perf: 23/72] libtracker-sparql: Propagate errors from FTS update/deletion




commit 111de39c82cf77a1d24a8e1885c282ba33ebcf64
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu May 19 12:57:45 2022 +0200

    libtracker-sparql: Propagate errors from FTS update/deletion
    
    These were warned in place, propagate them up to the machinery handling
    changes to the database.

 src/libtracker-sparql/core/tracker-data-update.c   | 26 +++++++++----
 .../core/tracker-db-interface-sqlite.c             | 44 +++++++++-------------
 .../core/tracker-db-interface-sqlite.h             |  6 ++-
 3 files changed, 39 insertions(+), 37 deletions(-)
---
diff --git a/src/libtracker-sparql/core/tracker-data-update.c 
b/src/libtracker-sparql/core/tracker-data-update.c
index ea25a862c..f2fd78a1e 100644
--- a/src/libtracker-sparql/core/tracker-data-update.c
+++ b/src/libtracker-sparql/core/tracker-data-update.c
@@ -846,6 +846,7 @@ tracker_data_resource_buffer_flush (TrackerData                      *data,
                TrackerProperty *prop;
                GArray *values;
                GPtrArray *properties;
+               gboolean retval;
 
                properties = NULL;
                g_hash_table_iter_init (&iter, resource->predicates);
@@ -862,11 +863,15 @@ tracker_data_resource_buffer_flush (TrackerData                      *data,
                if (properties) {
                        g_ptr_array_add (properties, NULL);
 
-                       tracker_db_interface_sqlite_fts_delete_text (iface,
-                                                                    database,
-                                                                    resource->id,
-                                                                    (const gchar **) properties->pdata);
+                       retval = tracker_db_interface_sqlite_fts_delete_text (iface,
+                                                                             database,
+                                                                             resource->id,
+                                                                             (const gchar **) 
properties->pdata,
+                                                                             error);
                        g_ptr_array_free (properties, TRUE);
+
+                       if (!retval)
+                               return;
                }
        }
 
@@ -1058,6 +1063,7 @@ tracker_data_resource_buffer_flush (TrackerData                      *data,
                TrackerProperty *prop;
                GArray *values;
                GPtrArray *properties;
+               gboolean retval;
 
                properties = NULL;
                g_hash_table_iter_init (&iter, resource->predicates);
@@ -1073,11 +1079,15 @@ tracker_data_resource_buffer_flush (TrackerData                      *data,
                if (properties) {
                        g_ptr_array_add (properties, NULL);
 
-                       tracker_db_interface_sqlite_fts_update_text (iface,
-                                                                    database,
-                                                                    resource->id,
-                                                                    (const gchar **) properties->pdata);
+                       retval = tracker_db_interface_sqlite_fts_update_text (iface,
+                                                                             database,
+                                                                             resource->id,
+                                                                             (const gchar **) 
properties->pdata,
+                                                                             error);
                        g_ptr_array_free (properties, TRUE);
+
+                       if (!retval)
+                               return;
                }
        }
 }
diff --git a/src/libtracker-sparql/core/tracker-db-interface-sqlite.c 
b/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
index 803698652..56dc573c6 100644
--- a/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
+++ b/src/libtracker-sparql/core/tracker-db-interface-sqlite.c
@@ -2368,10 +2368,11 @@ gboolean
 tracker_db_interface_sqlite_fts_update_text (TrackerDBInterface  *db_interface,
                                              const gchar         *database,
                                              TrackerRowid         id,
-                                             const gchar        **properties)
+                                             const gchar        **properties,
+                                             GError             **error)
 {
        TrackerDBStatement *stmt;
-       GError *error = NULL;
+       GError *inner_error = NULL;
        gchar *query;
 
        query = tracker_db_interface_sqlite_fts_create_update_query (db_interface,
@@ -2379,26 +2380,19 @@ tracker_db_interface_sqlite_fts_update_text (TrackerDBInterface  *db_interface,
                                                                     properties);
        stmt = tracker_db_interface_create_statement (db_interface,
                                                      TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE,
-                                                     &error,
+                                                     error,
                                                      query);
        g_free (query);
 
-        if (!stmt || error) {
-                if (error) {
-                        g_warning ("Could not create FTS insert statement: %s\n",
-                                   error->message);
-                        g_error_free (error);
-                }
+        if (!stmt)
                 return FALSE;
-        }
 
         tracker_db_statement_bind_int (stmt, 0, id);
-        tracker_db_statement_execute (stmt, &error);
+        tracker_db_statement_execute (stmt, &inner_error);
         g_object_unref (stmt);
 
-        if (error) {
-                g_warning ("Could not insert FTS text: %s", error->message);
-                g_error_free (error);
+        if (inner_error) {
+               g_propagate_prefixed_error (error, inner_error, "Could not insert FTS text: ");
                 return FALSE;
         }
 
@@ -2439,10 +2433,11 @@ gboolean
 tracker_db_interface_sqlite_fts_delete_text (TrackerDBInterface  *db_interface,
                                              const gchar         *database,
                                              TrackerRowid         rowid,
-                                             const gchar        **properties)
+                                             const gchar        **properties,
+                                             GError             **error)
 {
        TrackerDBStatement *stmt;
-       GError *error = NULL;
+       GError *inner_error = NULL;
        gchar *query;
 
        query = tracker_db_interface_sqlite_fts_create_delete_query (db_interface,
@@ -2450,25 +2445,20 @@ tracker_db_interface_sqlite_fts_delete_text (TrackerDBInterface  *db_interface,
                                                                     properties);
        stmt = tracker_db_interface_create_statement (db_interface,
                                                      TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE,
-                                                     &error,
+                                                     error,
                                                      query);
        g_free (query);
 
-       if (!stmt || error) {
-               g_warning ("Could not create FTS delete statement: %s",
-                          error ? error->message : "No error given");
-               g_clear_error (&error);
+       if (!stmt)
                return FALSE;
-       }
 
        tracker_db_statement_bind_int (stmt, 0, rowid);
-       tracker_db_statement_execute (stmt, &error);
+       tracker_db_statement_execute (stmt, &inner_error);
        g_object_unref (stmt);
 
-       if (error) {
-               g_warning ("Could not delete FTS text: %s", error->message);
-               g_error_free (error);
-               return FALSE;
+       if (inner_error) {
+               g_propagate_prefixed_error (error, inner_error, "Could not delete FTS text: ");
+                return FALSE;
        }
 
        return TRUE;
diff --git a/src/libtracker-sparql/core/tracker-db-interface-sqlite.h 
b/src/libtracker-sparql/core/tracker-db-interface-sqlite.h
index ea7d64af7..fedd27df3 100644
--- a/src/libtracker-sparql/core/tracker-db-interface-sqlite.h
+++ b/src/libtracker-sparql/core/tracker-db-interface-sqlite.h
@@ -70,12 +70,14 @@ gboolean            tracker_db_interface_sqlite_fts_alter_table        (TrackerD
 gboolean            tracker_db_interface_sqlite_fts_update_text        (TrackerDBInterface       
*db_interface,
                                                                         const gchar              *database,
                                                                         TrackerRowid              id,
-                                                                        const gchar             
**properties);
+                                                                        const gchar             **properties,
+                                                                        GError                  **error);
 
 gboolean            tracker_db_interface_sqlite_fts_delete_text        (TrackerDBInterface       *interface,
                                                                         const gchar              *database,
                                                                         TrackerRowid              rowid,
-                                                                        const gchar             
**properties);
+                                                                        const gchar             **properties,
+                                                                        GError                  **error);
 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]