EdsTest.Backend: add contacts as a batch, not one at a time
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Fri, 15 Mar 2013 18:22:38 +0000 (18:22 +0000)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Wed, 20 Mar 2013 13:40:26 +0000 (13:40 +0000)
This should make it much quicker to add contacts in bulk.

Bug https://bugzilla.gnome.org/show_bug.cgi?id=696104
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Philip Withnall <philip@tecnocode.co.uk>
tests/lib/eds/backend.vala

index 17edd5b..fc4e432 100644 (file)
@@ -193,25 +193,32 @@ public class EdsTest.Backend
 
   public async void commit_contacts_to_addressbook ()
     {
+      GLib.SList<E.Contact> contacts = null;
+
       this._contacts.reverse ();
+
       foreach (var c in this._contacts)
         {
           E.Contact contact = new E.Contact ();
 
           this._set_contact_fields (contact, c);
 
-          try
-            {
-              string added_uid;
-              yield this._addressbook.add_contact (contact,
-                  null, out added_uid);
-              this._e_contacts += (owned) added_uid;
-            }
-          catch (GLib.Error e)
-            {
-              GLib.warning ("Couldn't add contact: %s\n",
-                  e.message);
-            }
+          contacts.prepend (contact);
+        }
+
+      try
+        {
+          GLib.SList<string> uids;
+
+          yield this._addressbook.add_contacts (contacts, null, out uids);
+
+          foreach (unowned string uid in uids)
+            this._e_contacts += uid;
+        }
+      catch (GLib.Error e)
+        {
+          GLib.warning ("Couldn't add contacts: %s\n",
+              e.message);
         }
     }