summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels De Graef <nielsdegraef@gmail.com>2018-05-05 11:50:16 +0200
committerNiels De Graef <nielsdegraef@gmail.com>2018-05-05 11:54:10 +0200
commit7b441e3bbfcbe72e12ba694bd3f7082598059cca (patch)
treec8c16fc31fdbf85f5366b57c4c6d7fee0f9432d5
parent0f14d0baab2f221bd94cdce99606893eedbf3049 (diff)
downloadgnome-contacts-7b441e3bbfcbe72e12ba694bd3f7082598059cca.tar.gz
Revert "Store: add contacts in a separate thread."
This reverts commit 9c256a5c7917a01f844c43501468c4700a4fcc28. Tried adding multithreading a bit too naively at that point. It's possible to get it working using a Glib.RWLock, but that makes the code whole lot less clean, so I don't want to use that. In the long term, we need to think of a good strategy for this problem (such as possibly not having a separate arraylist for the Contacts anymore).
-rw-r--r--src/contacts-store.vala30
1 files changed, 7 insertions, 23 deletions
diff --git a/src/contacts-store.vala b/src/contacts-store.vala
index 5b7c715..3b75a88 100644
--- a/src/contacts-store.vala
+++ b/src/contacts-store.vala
@@ -176,20 +176,10 @@ public class Contacts.Store : GLib.Object {
var replaced_individuals = new HashMap<Individual?, Individual?> ();
var old_individuals = changes.get_keys();
- // At startup, a mass of contacts are added here: so, do this in a separate thread.
- var added_individuals = changes[null];
- if (!added_individuals.is_empty) {
- new Thread<void*> (null, () => {
- bulk_add (added_individuals);
- return null;
- });
- }
-
// Pick best replacements at joins
foreach (var old_individual in old_individuals) {
if (old_individual == null)
continue;
-
foreach (var new_individual in changes[old_individual]) {
if (new_individual == null)
continue;
@@ -212,6 +202,9 @@ public class Contacts.Store : GLib.Object {
// Removing an old individual.
var c = Contact.from_individual (old_individual);
remove (c);
+ } else if (new_individual != null) {
+ // Adding a new individual.
+ add (new Contact (this, new_individual));
}
}
@@ -238,9 +231,7 @@ public class Contacts.Store : GLib.Object {
if (i != main_individual) {
// Already replaced this old_individual, i.e. we're splitting
// old_individual. We just make this a new one.
- var new_contact = new Contact (this, i);
- this.contacts.add (new_contact);
- added (new_contact);
+ add (new Contact (this, i));
}
}
}
@@ -286,16 +277,9 @@ public class Contacts.Store : GLib.Object {
return contacts.read_only_view;
}
- private void bulk_add (Collection<Individual> indivs) {
- foreach (var individual in indivs) {
- var c = new Contact (this, individual);
- this.contacts.add (c);
- // Since we do this in a separate thread, use Idle.add.
- Idle.add (() => {
- added (c);
- return false;
- });
- }
+ private void add (Contact c) {
+ contacts.add (c);
+ added (c);
}
private void remove (Contact c) {