Commit 2f442b49 authored by Philip Withnall's avatar Philip Withnall
Browse files

core: Replace the linking step in IA.ensure_individual_property_writeable()

It’s a waste of time to create a new Persona to ensure the property is
writeable, then create _another_ new Persona to link it to the Individual.
Why not just create the writeable Persona so that it’s automatically linked
to the Individual?

Helps: https://bugzilla.gnome.org/show_bug.cgi?id=629537
parent 34e0b442
......@@ -1989,8 +1989,17 @@ public class Folks.IndividualAggregator : Object
debug ("ensure_individual_property_writeable: %s, %s",
individual.id, property_name);
/* See if the individual already contains the property we want. */
foreach (var p1 in individual.personas)
var p = yield this._ensure_personas_property_writeable (
individual.personas, property_name);
return p;
}
private async Persona _ensure_personas_property_writeable (
Set<Persona> personas, string property_name)
throws IndividualAggregatorError
{
/* See if the persona set already contains the property we want. */
foreach (var p1 in personas)
{
if (property_name in p1.writeable_properties)
{
......@@ -2002,7 +2011,7 @@ public class Folks.IndividualAggregator : Object
/* Otherwise, create a new persona in the writeable store. If the
* writeable store doesn't exist or doesn't support writing to the given
* property, we try the other persona stores. */
var details = new HashTable<string, Value?> (str_hash, str_equal);
var details = this._build_linking_details (personas);
Persona? new_persona = null;
if (this._primary_store != null &&
......@@ -2067,20 +2076,8 @@ public class Folks.IndividualAggregator : Object
property_name);
}
/* Link the persona to the existing individual. We can guarantee
* new_persona != null because we'd have bailed out above otherwise. */
var linking_personas = new HashSet<Persona> ();
linking_personas.add ((!) new_persona);
foreach (var p2 in individual.personas)
{
linking_personas.add (p2);
}
debug (" Linking personas to ensure %s property is writeable.",
property_name);
yield this.link_personas (linking_personas);
/* We can guarantee new_persona != null because we'd have bailed out above
* otherwise. */
return (!) new_persona;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment