[folks] core: Be more thorough when removing individuals from the link map



commit 55abd8380a639d7e475483fcd0121d7b6552d51c
Author: Philip Withnall <philip tecnocode co uk>
Date:   Tue Sep 6 22:16:44 2011 +0100

    core: Be more thorough when removing individuals from the link map
    
    Since the values of personas' linkable properties could've changed since we
    added them to the link map, we have to be more thorough when removing
    individuals from the map. We therefore now remove them by examining all the
    values in the map, and removing every mapping to the individual we're
    interested in.
    
    Helps: bgo#656689

 folks/individual-aggregator.vala |   51 +++++++++++++++-----------------------
 1 files changed, 20 insertions(+), 31 deletions(-)
---
diff --git a/folks/individual-aggregator.vala b/folks/individual-aggregator.vala
index 8b89736..cb8a316 100644
--- a/folks/individual-aggregator.vala
+++ b/folks/individual-aggregator.vala
@@ -937,37 +937,28 @@ public class Folks.IndividualAggregator : Object
         }
     }
 
-  private void _remove_persona_from_link_map (Persona persona)
+  /* We remove individuals as a whole from the link map, rather than iterating
+   * through the link map keys generated by their personas (as in
+   * _add_persona_to_link_map()) because the values of the personas' linkable
+   * properties may well have changed since we added the personas to the link
+   * map. If that's the case, we don't want to end up leaving stale entries in
+   * the link map, since that *will* cause problems later on. */
+  private void _remove_individual_from_link_map (Individual individual)
     {
-      this._link_map.remove (persona.iid);
+      debug ("Removing Individual '%s' from the link map.", individual.id);
 
-      if (persona.store.trust_level == PersonaStoreTrust.FULL)
-        {
-          debug ("    Removing links to %s:", persona.uid);
+      var iter = HashTableIter<string, Individual> (this._link_map);
+      string link_key;
+      Individual link_individual;
 
-          /* Remove maps from the Persona's linkable properties to
-           * Individuals. Add the Individuals to a list of Individuals to be
-           * removed. */
-          foreach (unowned string prop_name in persona.linkable_properties)
+      while (iter.next (out link_key, out link_individual) == true)
+        {
+          if (link_individual == individual)
             {
-              debug ("        %s", prop_name);
-
-              /* FIXME: can't be var because of bgo#638208 */
-              unowned ObjectClass pclass = persona.get_class ();
-              if (pclass.find_property (prop_name) == null)
-                {
-                  warning (
-                      /* Translators: the parameter is a property name. */
-                      _("Unknown property '%s' in linkable property list."),
-                      prop_name);
-                  continue;
-                }
+              debug ("    %s â %s (%p)",
+                  link_key, link_individual.id, link_individual);
 
-              persona.linkable_property_to_links (prop_name, (linking_value) =>
-                {
-                  debug ("            %s", linking_value);
-                  this._link_map.remove (linking_value);
-                });
+              iter.remove ();
             }
         }
     }
@@ -1006,8 +997,6 @@ public class Folks.IndividualAggregator : Object
               individuals_changes.set (ind, null);
             }
 
-          /* Remove the Persona's links from the link map */
-          this._remove_persona_from_link_map (persona);
         }
 
       /* Remove the Individuals which were pointed to by the linkable properties
@@ -1035,9 +1024,6 @@ public class Folks.IndividualAggregator : Object
                 continue;
 
               relinked_personas.add (persona);
-
-              /* Remove links to the Persona */
-              this._remove_persona_from_link_map (persona);
             }
 
           if (user == individual)
@@ -1045,6 +1031,9 @@ public class Folks.IndividualAggregator : Object
 
           this._disconnect_from_individual (individual);
           individual.personas = null;
+
+          /* Remove the Individual's links from the link map */
+          this._remove_individual_from_link_map (individual);
         }
 
       debug ("Adding Personas:");



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