[gnome-contacts] Revert "Store: add contacts in a separate thread."
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] Revert "Store: add contacts in a separate thread."
- Date: Sat, 5 May 2018 09:54:48 +0000 (UTC)
commit 7b441e3bbfcbe72e12ba694bd3f7082598059cca
Author: Niels De Graef <nielsdegraef gmail com>
Date: Sat May 5 11:50:16 2018 +0200
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).
src/contacts-store.vala | 30 +++++++-----------------------
1 file 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) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]