[tracker] libtracker-data: Handle inserts where the subproperty cardinality is larger than the parents'



commit 816104aeb8585913d76ccde8df99192c48d554ea
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Mar 13 12:55:30 2016 +0100

    libtracker-data: Handle inserts where the subproperty cardinality is larger than the parents'
    
    This is the case of properties like nco:creator, which has unrestricted
    cardinality, but is subproperty of dc:creator, which has its cardinality
    limited to 1.
    
    In cases like this, inserts of multiple values shouldn't fail because of
    the restricted cardinality in superproperties which this one supersedes.
    So make it sure we don't propagate inserts to superproperties if its
    cardinality is already satisfied.
    
    Updates already work fine in this regard, with the difference that it's
    the last value which will prevail in the single-valued superproperty, this
    seems consistent with the nature of updates.

 src/libtracker-data/tracker-data-update.c |   33 +++++++++++++++++-----------
 1 files changed, 20 insertions(+), 13 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 9cdfcaf..4ae923e 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -1652,29 +1652,36 @@ cache_insert_metadata_decomposed (TrackerProperty  *property,
        GError             *new_error = NULL;
        gboolean            change = FALSE;
 
+       /* read existing property values */
+       old_values = get_old_property_values (property, &new_error);
+       if (new_error) {
+               g_propagate_error (error, new_error);
+               return FALSE;
+       }
+
        /* also insert super property values */
        super_properties = tracker_property_get_super_properties (property);
+       multiple_values = tracker_property_get_multiple_values (property);
+
        while (*super_properties) {
-               change |= cache_insert_metadata_decomposed (*super_properties, value, value_id,
-                                                           graph, graph_id, &new_error);
-               if (new_error) {
-                       g_propagate_error (error, new_error);
-                       return FALSE;
+               gboolean super_is_multi;
+
+               super_is_multi = tracker_property_get_multiple_values (*super_properties);
+
+               if (super_is_multi || old_values->len == 0) {
+                       change |= cache_insert_metadata_decomposed (*super_properties, value, value_id,
+                                                                   graph, graph_id, &new_error);
+                       if (new_error) {
+                               g_propagate_error (error, new_error);
+                               return FALSE;
+                       }
                }
                super_properties++;
        }
 
-       multiple_values = tracker_property_get_multiple_values (property);
        table_name = tracker_property_get_table_name (property);
        field_name = tracker_property_get_name (property);
 
-       /* read existing property values */
-       old_values = get_old_property_values (property, &new_error);
-       if (new_error) {
-               g_propagate_error (error, new_error);
-               return FALSE;
-       }
-
        if (value) {
                string_to_gvalue (value, tracker_property_get_data_type (property), &gvalue, &new_error);
                if (new_error) {


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