[tracker/wip/carlosg/backports-for-3-1: 14/16] libtracker-data: Mark specific properties as being deleted




commit be2c93a6ab94d36ab27bac7aeb90f91edcda97e7
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue May 25 13:52:31 2021 +0200

    libtracker-data: Mark specific properties as being deleted
    
    When dealing with single-valued properties that are deleted,
    we rely on the batch being explicitly flushed so that property
    deletions and insertions are not mixed up. We don't need to do this,
    instead we can tag individual properties as being deleted, so that
    we can mix deletions and insertions in the same row update.
    
    We were failing to do this explicit flushing at places in
    update_resource() which was leading to some triples being ignored
    (deemed as being deleted too, despite them being actually on their
    way to insertion).
    
    The tip of the iceberg here was a FTS property, as this
    circumstance left the real table column content and the fts5
    contentless tokenization data for that corresponding column out
    of sync. This resulted in FTS corrupted index on tracker-miner-fs-3
    after:
    
     $ touch ~/lalala
     $ rm ~/lalala
     $ tracker3 search lalala
    
    Making property deletion a per-property thing, we can avoid the
    explicit flush, write correctly the missing properties (nfo:fileName
    in the tracker:FileSystem graph, in this case), and make the column
    content match the FTS tokens again.
    
    Fixes: https://gitlab.gnome.org/GNOME/tracker/-/issues/308

 src/libtracker-data/tracker-data-update.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 7ed6beed2..80474814b 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -87,12 +87,12 @@ struct _TrackerDataUpdateBufferProperty {
        const gchar *name;
        GValue value;
        guint delete_all_values : 1;
+       guint delete_value : 1;
 };
 
 struct _TrackerDataUpdateBufferTable {
        gboolean insert;
        gboolean delete_row;
-       gboolean delete_value;
        gboolean multiple_values;
        TrackerClass *class;
        /* TrackerDataUpdateBufferProperty */
@@ -641,7 +641,6 @@ cache_delete_all_values (TrackerData *data,
        property.delete_all_values = TRUE;
 
        table = cache_ensure_table (data, table_name, TRUE);
-       table->delete_value = TRUE;
        g_array_append_val (table->properties, property);
 }
 
@@ -656,12 +655,12 @@ cache_delete_value (TrackerData *data,
        TrackerDataUpdateBufferProperty  property = { 0 };
 
        property.name = field_name;
+       property.delete_value = TRUE;
 
        g_value_init (&property.value, G_VALUE_TYPE (value));
        g_value_copy (value, &property.value);
 
        table = cache_ensure_table (data, table_name, multiple_values);
-       table->delete_value = TRUE;
        g_array_append_val (table->properties, property);
 }
 
@@ -832,12 +831,12 @@ tracker_data_resource_buffer_flush (TrackerData                      *data,
                        for (i = 0; i < table->properties->len; i++) {
                                property = &g_array_index (table->properties, 
TrackerDataUpdateBufferProperty, i);
 
-                               if (table->delete_value && property->delete_all_values) {
+                               if (property->delete_all_values) {
                                        stmt = tracker_db_interface_create_vstatement (iface, 
TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &actual_error,
                                                                                       "DELETE FROM 
\"%s\".\"%s\" WHERE ID = ?",
                                                                                       database,
                                                                                       table_name);
-                               } else if (table->delete_value) {
+                               } else if (property->delete_value) {
                                        /* delete rows for multiple value properties */
                                        stmt = tracker_db_interface_create_vstatement (iface, 
TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &actual_error,
                                                                                       "DELETE FROM 
\"%s\".\"%s\" WHERE ID = ? AND \"%s\" = ?",
@@ -968,7 +967,7 @@ tracker_data_resource_buffer_flush (TrackerData                      *data,
 
                        for (i = 0; i < table->properties->len; i++) {
                                property = &g_array_index (table->properties, 
TrackerDataUpdateBufferProperty, i);
-                               if (table->delete_value) {
+                               if (property->delete_value) {
                                        /* just set value to NULL for single value properties */
                                        tracker_db_statement_bind_null (stmt, param++);
                                } else {


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