[gnome-contacts/nielsdg/link-duplicate-contacts] store: Make sure we don't add individuals twice
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts/nielsdg/link-duplicate-contacts] store: Make sure we don't add individuals twice
- Date: Tue, 11 Oct 2022 09:01:15 +0000 (UTC)
commit 6ba0c4b3fb4684670ef631c67482f1bbd4f7ea86
Author: Niels De Graef <nielsdegraef gmail com>
Date: Tue Oct 11 10:31:06 2022 +0200
store: Make sure we don't add individuals twice
An individual can appear several times in the `changes` argument of the
`IndividualAggregator`'s `individuals-changed-detailed` signal, in the
case of linking. When 2 Individuals are linked -let's call them A and
B- into a single Individual C, then the signal will be emitted with the
following map:
```
A -> C
B -> C
```
In other words, C will show up twice in the list of values. Since we
weren't checking whether an individual already existed before adding it
to the `to_add` list, duplicates were a possibility. This should no
longer be the case (and from a quick check, it doesn't have any
non-negligible performance impact either).
Fixes: https://gitlab.gnome.org/GNOME/gnome-contacts/-/issues/247
src/contacts-store.vala | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
---
diff --git a/src/contacts-store.vala b/src/contacts-store.vala
index 7a70cad6..c359a379 100644
--- a/src/contacts-store.vala
+++ b/src/contacts-store.vala
@@ -188,7 +188,7 @@ public class Contacts.Store : GLib.Object {
if (individual != null)
to_remove.add (individual);
foreach (var new_i in changes[individual]) {
- if (new_i != null)
+ if (new_i != null && !to_add.find (new_i, null))
to_add.add (new_i);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]