[folks] Ensure duplicate Individuals don't enter candidate_inds when aggregating
- From: Travis Reitter <treitter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Ensure duplicate Individuals don't enter candidate_inds when aggregating
- Date: Fri, 20 Aug 2010 15:51:46 +0000 (UTC)
commit f2fc13b30ab64f82a8681f7466fed7d5b15cd1da
Author: Philip Withnall <philip withnall collabora co uk>
Date: Fri Aug 20 12:22:13 2010 +0100
Ensure duplicate Individuals don't enter candidate_inds when aggregating
If Individuals matched on more than one property, they would appear in the
list of candidate Individuals multiple times, causing the resulting linked
Individual to contain duplicate Personas and Bad Things to happen.
Helps: bgo#626544
folks/individual-aggregator.vala | 21 +++++++++++++++++++--
1 files changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/folks/individual-aggregator.vala b/folks/individual-aggregator.vala
index 4c0c4e1..bec57c6 100644
--- a/folks/individual-aggregator.vala
+++ b/folks/individual-aggregator.vala
@@ -216,7 +216,19 @@ public class Folks.IndividualAggregator : Object
{
unowned Persona persona = (Persona) p;
PersonaStoreTrust trust_level = persona.store.trust_level;
+
+ /* These are the Individuals whose Personas will be linked together
+ * to form the `final_individual`. We keep a list of the Individuals
+ * for fast iteration, but also keep a set to ensure that we don't
+ * get duplicate Individuals in the list.
+ * Since a given Persona can only be part of one Individual, and the
+ * code in Persona._set_personas() ensures that there are no duplicate
+ * Personas in a given Individual, ensuring that there are no
+ * duplicate Individuals in `candidate_inds` guarantees that there
+ * will be no duplicate Personas in the `final_individual`. */
GLib.List<Individual> candidate_inds = null;
+ HashSet<Individual> candidate_ind_set = new HashSet<Individual> ();
+
GLib.List<Persona> final_personas = new GLib.List<Persona> ();
Individual final_individual = null;
@@ -232,6 +244,7 @@ public class Folks.IndividualAggregator : Object
debug (" Found candidate individual '%s' by IID.",
candidate_ind.id);
candidate_inds.prepend (candidate_ind);
+ candidate_ind_set.add (candidate_ind);
}
}
@@ -253,8 +266,12 @@ public class Folks.IndividualAggregator : Object
{
Individual candidate_ind =
this.link_map.lookup ((string) l);
- if (candidate_ind != null)
- candidate_inds.prepend (candidate_ind);
+ if (candidate_ind != null &&
+ !candidate_ind_set.contains (candidate_ind))
+ {
+ candidate_inds.prepend (candidate_ind);
+ candidate_ind_set.add (candidate_ind);
+ }
});
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]