[geary] Remove lazy_list_* operations and support code: Bug #713878



commit 1ec6852f824007f7d566dacbc28d3857789f28ec
Author: Jim Nelson <jim yorba org>
Date:   Fri Oct 24 12:38:09 2014 -0700

    Remove lazy_list_* operations and support code: Bug #713878
    
    The lazy_list_* operations outlived their purpose long ago and now
    represent dead interfaces and unused code paths.

 src/engine/abstract/geary-abstract-folder.vala     |   41 --------
 src/engine/api/geary-folder.vala                   |   34 +------
 .../imap-engine/imap-engine-minimal-folder.vala    |  100 ++++----------------
 .../imap-engine-abstract-list-email.vala           |   32 ++-----
 .../replay-ops/imap-engine-list-email-by-id.vala   |   20 +---
 .../imap-engine-list-email-by-sparse-id.vala       |   20 +---
 .../imap-engine-server-search-email.vala           |    4 +-
 7 files changed, 43 insertions(+), 208 deletions(-)
---
diff --git a/src/engine/abstract/geary-abstract-folder.vala b/src/engine/abstract/geary-abstract-folder.vala
index 8a5dc68..aeed7cd 100644
--- a/src/engine/abstract/geary-abstract-folder.vala
+++ b/src/engine/abstract/geary-abstract-folder.vala
@@ -104,51 +104,10 @@ public abstract class Geary.AbstractFolder : BaseObject, Geary.Folder {
         int count, Geary.Email.Field required_fields, Folder.ListFlags flags, Cancellable? cancellable = 
null)
         throws Error;
     
-    public virtual void lazy_list_email_by_id(Geary.EmailIdentifier? initial_id, int count,
-        Geary.Email.Field required_fields, Folder.ListFlags flags, EmailCallback cb, Cancellable? 
cancellable = null) {
-        do_lazy_list_email_by_id_async.begin(initial_id, count, required_fields, flags, cb,
-            cancellable);
-    }
-    
-    private async void do_lazy_list_email_by_id_async(Geary.EmailIdentifier? initial_id, int count,
-        Geary.Email.Field required_fields, Folder.ListFlags flags, EmailCallback cb, Cancellable? 
cancellable) {
-        try {
-            Gee.List<Geary.Email>? list = yield list_email_by_id_async(initial_id, count,
-                required_fields, flags, cancellable);
-            if (list != null && list.size > 0)
-                cb(list, null);
-            
-            cb(null, null);
-        } catch (Error err) {
-            cb(null, err);
-        }
-    }
-    
     public abstract async Gee.List<Geary.Email>? list_email_by_sparse_id_async(
         Gee.Collection<Geary.EmailIdentifier> ids, Geary.Email.Field required_fields, Folder.ListFlags flags,
         Cancellable? cancellable = null) throws Error;
     
-    public virtual void lazy_list_email_by_sparse_id(Gee.Collection<Geary.EmailIdentifier> ids,
-        Geary.Email.Field required_fields, Folder.ListFlags flags, EmailCallback cb,
-        Cancellable? cancellable = null) {
-        do_lazy_list_email_by_sparse_id_async.begin(ids, required_fields, flags, cb, cancellable);
-    }
-    
-    private async void do_lazy_list_email_by_sparse_id_async(Gee.Collection<Geary.EmailIdentifier> ids,
-        Geary.Email.Field required_fields, Folder.ListFlags flags, EmailCallback cb,
-        Cancellable? cancellable) {
-        try {
-            Gee.List<Geary.Email>? list = yield list_email_by_sparse_id_async(ids,
-                required_fields, flags, cancellable);
-            if (list != null && list.size > 0)
-                cb(list, null);
-            
-            cb(null, null);
-        } catch (Error err) {
-            cb(null, err);
-        }
-    }
-    
     public abstract async Gee.Map<Geary.EmailIdentifier, Geary.Email.Field>? list_local_email_fields_async(
         Gee.Collection<Geary.EmailIdentifier> ids, Cancellable? cancellable = null) throws Error;
     
diff --git a/src/engine/api/geary-folder.vala b/src/engine/api/geary-folder.vala
index 683c513..69c6d30 100644
--- a/src/engine/api/geary-folder.vala
+++ b/src/engine/api/geary-folder.vala
@@ -4,8 +4,6 @@
  * (version 2.1 or later).  See the COPYING file in this distribution.
  */
 
-public delegate void Geary.EmailCallback(Gee.List<Geary.Email>? emails, Error? err);
-
 public interface Geary.Folder : BaseObject {
     public enum OpenState {
         CLOSED,
@@ -100,8 +98,7 @@ public interface Geary.Folder : BaseObject {
          */
         FORCE_UPDATE,
         /**
-         * Include the provided EmailIdentifier (only respected by { link list_email_by_id_async} and
-         * { link lazy_list_email_by_id}).
+         * Include the provided EmailIdentifier (only respected by { link list_email_by_id_async}.
          */
         INCLUDING_ID,
         /**
@@ -431,25 +428,12 @@ public interface Geary.Folder : BaseObject {
         throws Error;
     
     /**
-     * Similar in contract to lazy_list_email_async(), but uses Geary.EmailIdentifier rather than
-     * positional addressing, much like list_email_by_id_async().  See that method for more
-     * information on its contract and how the count and flags parameters work.
-     *
-     * Like the other "lazy" methods, this method will call EmailCallback while the operation is
-     * processing.  This method does not block.
-     *
-     * The Folder must be opened prior to attempting this operation.
-     */
-    public abstract void lazy_list_email_by_id(Geary.EmailIdentifier? initial_id, int count,
-        Geary.Email.Field required_fields, ListFlags flags, EmailCallback cb, Cancellable? cancellable = 
null);
-    
-    /**
      * Similar in contract to { link list_email_by_id_async}, but uses a list of
      * { link Geary.EmailIdentifier}s rather than a range.
      *
      * Any Gee.Collection is accepted for EmailIdentifiers, but the returned list will only contain
      * one email for each requested; duplicates are ignored.  ListFlags.INCLUDING_ID is ignored
-     * for this call and { link lazy_list_email_by_sparse_id}.
+     * for this call.
      *
      * The Folder must be opened prior to attempting this operation.
      */
@@ -458,20 +442,6 @@ public interface Geary.Folder : BaseObject {
         Cancellable? cancellable = null) throws Error;
     
     /**
-     * See { link list_email_by_id_async} and { link list_email_by_sparse_id_async}
-     * for more information on { link EmailIdentifier}s and how the flags and callback parameter
-     * works.
-     *
-     * Like the other "lazy" method, this method will call EmailCallback while the operation is
-     * processing.  This method does not block.
-     *
-     * The Folder must be opened prior to attempting this operation.
-     */
-    public abstract void lazy_list_email_by_sparse_id(Gee.Collection<Geary.EmailIdentifier> ids,
-        Geary.Email.Field required_fields, ListFlags flags, EmailCallback cb,
-        Cancellable? cancellable = null);
-    
-    /**
      * Returns the locally available Geary.Email.Field fields for the specified emails.  If a
      * list or fetch operation occurs on the emails that specifies a field not returned here,
      * the Engine will either have to go out to the remote server to get it, or (if
diff --git a/src/engine/imap-engine/imap-engine-minimal-folder.vala 
b/src/engine/imap-engine/imap-engine-minimal-folder.vala
index ceb9f2c..c8b1aa6 100644
--- a/src/engine/imap-engine/imap-engine-minimal-folder.vala
+++ b/src/engine/imap-engine/imap-engine-minimal-folder.vala
@@ -1114,110 +1114,49 @@ private class Geary.ImapEngine.MinimalFolder : Geary.AbstractFolder, Geary.Folde
     }
     
     //
-    // list_email_by_id variants
+    // list email variants
     //
     
     public override async Gee.List<Geary.Email>? list_email_by_id_async(Geary.EmailIdentifier? initial_id,
         int count, Geary.Email.Field required_fields, Folder.ListFlags flags,
         Cancellable? cancellable = null) throws Error {
-        Gee.List<Geary.Email> accumulator = new Gee.ArrayList<Geary.Email>();
-        yield do_list_email_by_id_async("list_email_by_id_async", initial_id, count, required_fields,
-            flags, accumulator, null, cancellable);
-        
-        return !accumulator.is_empty ? accumulator : null;
-    }
-    
-    public override void lazy_list_email_by_id(Geary.EmailIdentifier? initial_id, int count,
-        Geary.Email.Field required_fields, Folder.ListFlags flags, EmailCallback cb,
-        Cancellable? cancellable = null) {
-        do_lazy_list_email_by_id_async.begin(initial_id, count, required_fields, flags, cb, cancellable);
-    }
-    
-    private async void do_lazy_list_email_by_id_async(Geary.EmailIdentifier? initial_id, int count,
-        Geary.Email.Field required_fields, Folder.ListFlags flags, EmailCallback cb, Cancellable? 
cancellable) {
-        try {
-            yield do_list_email_by_id_async("lazy_list_email_by_id", initial_id, count, required_fields,
-                flags, null, cb, cancellable);
-        } catch (Error err) {
-            cb(null, err);
-        }
-    }
-    
-    private async void do_list_email_by_id_async(string method, Geary.EmailIdentifier? initial_id,
-        int count, Geary.Email.Field required_fields, Folder.ListFlags flags,
-        Gee.List<Geary.Email>? accumulator, EmailCallback? cb, Cancellable? cancellable) throws Error {
-        check_open(method);
-        check_flags(method, flags);
+        check_open("list_email_by_id_async");
+        check_flags("list_email_by_id_async", flags);
         if (initial_id != null)
-            check_id(method, initial_id);
+            check_id("list_email_by_id_async", initial_id);
         
-        if (count == 0) {
-            // signal finished
-            if (cb != null)
-                cb(null, null);
-            
-            return;
-        }
+        if (count == 0)
+            return null;
         
         // Schedule list operation and wait for completion.
         ListEmailByID op = new ListEmailByID(this, (ImapDB.EmailIdentifier) initial_id, count,
-            required_fields, flags, accumulator, cb, cancellable);
+            required_fields, flags, cancellable);
         replay_queue.schedule(op);
         
         yield op.wait_for_ready_async(cancellable);
+        
+        return !op.accumulator.is_empty ? op.accumulator : null;
     }
     
-    //
-    // list_email_by_sparse_id variants
-    //
-    
     public async override Gee.List<Geary.Email>? list_email_by_sparse_id_async(
         Gee.Collection<Geary.EmailIdentifier> ids, Geary.Email.Field required_fields, Folder.ListFlags flags,
         Cancellable? cancellable = null) throws Error {
-        Gee.ArrayList<Geary.Email> accumulator = new Gee.ArrayList<Geary.Email>();
-        yield do_list_email_by_sparse_id_async("list_email_by_sparse_id_async", ids, required_fields,
-            flags, accumulator, null, cancellable);
+        check_open("list_email_by_sparse_id_async");
+        check_flags("list_email_by_sparse_id_async", flags);
+        check_ids("list_email_by_sparse_id_async", ids);
         
-        return (accumulator.size > 0) ? accumulator : null;
-    }
-    
-    public override void lazy_list_email_by_sparse_id(Gee.Collection<Geary.EmailIdentifier> ids,
-        Geary.Email.Field required_fields, Folder.ListFlags flags, EmailCallback cb, Cancellable? 
cancellable = null) {
-        do_lazy_list_email_by_sparse_id_async.begin(ids, required_fields, flags, cb, cancellable);
-    }
-    
-    private async void do_lazy_list_email_by_sparse_id_async(Gee.Collection<Geary.EmailIdentifier> ids,
-        Geary.Email.Field required_fields, Folder.ListFlags flags, EmailCallback cb, Cancellable? 
cancellable) {
-        try {
-            yield do_list_email_by_sparse_id_async("lazy_list_email_by_sparse_id", ids, required_fields,
-                flags, null, cb, cancellable);
-        } catch (Error err) {
-            cb(null, err);
-        }
-    }
-    
-    private async void do_list_email_by_sparse_id_async(string method,
-        Gee.Collection<Geary.EmailIdentifier> ids, Geary.Email.Field required_fields, Folder.ListFlags flags,
-        Gee.List<Geary.Email>? accumulator, EmailCallback? cb, Cancellable? cancellable = null) throws Error 
{
-        check_open(method);
-        check_flags(method, flags);
-        check_ids(method, ids);
-        
-        if (ids.size == 0) {
-            // signal finished
-            if (cb != null)
-                cb(null, null);
-            
-            return;
-        }
+        if (ids.size == 0)
+            return null;
         
         // Schedule list operation and wait for completion.
         // TODO: Break up requests to avoid hogging the queue
         ListEmailBySparseID op = new ListEmailBySparseID(this, (Gee.Collection<ImapDB.EmailIdentifier>) ids,
-            required_fields, flags, accumulator, cb, cancellable);
+            required_fields, flags, cancellable);
         replay_queue.schedule(op);
         
         yield op.wait_for_ready_async(cancellable);
+        
+        return !op.accumulator.is_empty ? op.accumulator : null;
     }
     
     public override async Gee.Map<Geary.EmailIdentifier, Geary.Email.Field>? list_local_email_fields_async(
@@ -1356,9 +1295,8 @@ private class Geary.ImapEngine.MinimalFolder : Geary.AbstractFolder, Geary.Folde
         
         debug("%s: find_earliest_email_async: %s", to_string(), criteria.to_string());
         
-        Gee.List<Geary.Email> accumulator = new Gee.ArrayList<Geary.Email>();
         ServerSearchEmail op = new ServerSearchEmail(this, criteria, Geary.Email.Field.NONE,
-            accumulator, cancellable);
+            cancellable);
         
         // need to check again due to the yield in the above conditional block
         check_open("find_earliest_email_async.schedule operation");
@@ -1370,7 +1308,7 @@ private class Geary.ImapEngine.MinimalFolder : Geary.AbstractFolder, Geary.Folde
         
         // find earliest ID; because all Email comes from Folder, UID should always be present
         ImapDB.EmailIdentifier? earliest_id = null;
-        foreach (Geary.Email email in accumulator) {
+        foreach (Geary.Email email in op.accumulator) {
             ImapDB.EmailIdentifier email_id = (ImapDB.EmailIdentifier) email.id;
             
             if (earliest_id == null || email_id.uid.compare_to(earliest_id.uid) < 0)
diff --git a/src/engine/imap-engine/replay-ops/imap-engine-abstract-list-email.vala 
b/src/engine/imap-engine/replay-ops/imap-engine-abstract-list-email.vala
index 1e76607..4f1a3e2 100644
--- a/src/engine/imap-engine/replay-ops/imap-engine-abstract-list-email.vala
+++ b/src/engine/imap-engine/replay-ops/imap-engine-abstract-list-email.vala
@@ -53,24 +53,23 @@ private abstract class Geary.ImapEngine.AbstractListEmail : Geary.ImapEngine.Sen
         }
     }
     
+    // The accumulated Email from the list operation.  Should only be accessed once the operation
+    // has completed.
+    public Gee.List<Geary.Email> accumulator = new Gee.ArrayList<Geary.Email>();
+    
     protected MinimalFolder owner;
     protected Geary.Email.Field required_fields;
-    protected Gee.List<Geary.Email>? accumulator = null;
-    protected weak EmailCallback? cb;
     protected Cancellable? cancellable;
     protected Folder.ListFlags flags;
     
     private Gee.HashMap<Imap.UID, Geary.Email.Field> unfulfilled = new Gee.HashMap<Imap.UID, 
Geary.Email.Field>();
     
     public AbstractListEmail(string name, MinimalFolder owner, Geary.Email.Field required_fields,
-        Folder.ListFlags flags, Gee.List<Geary.Email>? accumulator, EmailCallback? cb,
-        Cancellable? cancellable) {
+        Folder.ListFlags flags, Cancellable? cancellable) {
         base(name);
         
         this.owner = owner;
         this.required_fields = required_fields;
-        this.accumulator = accumulator;
-        this.cb = cb;
         this.cancellable = cancellable;
         this.flags = flags;
     }
@@ -100,11 +99,9 @@ private abstract class Geary.ImapEngine.AbstractListEmail : Geary.ImapEngine.Sen
     public override void notify_remote_removed_ids(Gee.Collection<ImapDB.EmailIdentifier> ids) {
         // remove email already picked up from local store ... for email reported via the
         // callback, too late
-        if (accumulator != null) {
-            Collection.remove_if<Geary.Email>(accumulator, (email) => {
-                return ids.contains((ImapDB.EmailIdentifier) email.id);
-            });
-        }
+        Collection.remove_if<Geary.Email>(accumulator, (email) => {
+            return ids.contains((ImapDB.EmailIdentifier) email.id);
+        });
         
         // remove from unfulfilled list, as there's now nothing to fetch from the server
         // NOTE: Requires UID to work; this *should* always work, as the EmailIdentifier should
@@ -163,17 +160,8 @@ private abstract class Geary.ImapEngine.AbstractListEmail : Geary.ImapEngine.Sen
         }
         
         // report merged emails
-        if (result_list.size > 0) {
-            if (accumulator != null)
-                accumulator.add_all(result_list);
-            
-            if (cb != null)
-                cb(result_list, null);
-        }
-        
-        // done
-        if (cb != null)
-            cb(null, null);
+        if (result_list.size > 0)
+            accumulator.add_all(result_list);
         
         // signal
         if (created_ids.size > 0) {
diff --git a/src/engine/imap-engine/replay-ops/imap-engine-list-email-by-id.vala 
b/src/engine/imap-engine/replay-ops/imap-engine-list-email-by-id.vala
index bd3f3d1..af07b35 100644
--- a/src/engine/imap-engine/replay-ops/imap-engine-list-email-by-id.vala
+++ b/src/engine/imap-engine/replay-ops/imap-engine-list-email-by-id.vala
@@ -11,9 +11,8 @@ private class Geary.ImapEngine.ListEmailByID : Geary.ImapEngine.AbstractListEmai
     private Imap.UID? initial_uid = null;
     
     public ListEmailByID(MinimalFolder owner, ImapDB.EmailIdentifier? initial_id, int count,
-        Geary.Email.Field required_fields, Folder.ListFlags flags, Gee.List<Geary.Email>? accumulator,
-        EmailCallback? cb, Cancellable? cancellable) {
-        base ("ListEmailByID", owner, required_fields, flags, accumulator, cb, cancellable);
+        Geary.Email.Field required_fields, Folder.ListFlags flags, Cancellable? cancellable) {
+        base ("ListEmailByID", owner, required_fields, flags, cancellable);
         
         this.initial_id = initial_id;
         this.count = count;
@@ -61,13 +60,8 @@ private class Geary.ImapEngine.ListEmailByID : Geary.ImapEngine.AbstractListEmai
         
         // report fulfilled items
         fulfilled_count = fulfilled.size;
-        if (fulfilled_count > 0) {
-            if (accumulator != null)
-                accumulator.add_all(fulfilled);
-            
-            if (cb != null)
-                cb(fulfilled, null);
-        }
+        if (fulfilled_count > 0)
+            accumulator.add_all(fulfilled);
         
         // determine if everything was listed
         bool finished = false;
@@ -95,12 +89,8 @@ private class Geary.ImapEngine.ListEmailByID : Geary.ImapEngine.AbstractListEmai
         
         // local-only operations stop here; also, since the local store is normalized from the top
         // of the vector on down, if enough items came back fulfilled, then done
-        if (finished) {
-            if (cb != null)
-                cb(null, null);
-            
+        if (finished)
             return ReplayOperation.Status.COMPLETED;
-        }
         
         return ReplayOperation.Status.CONTINUE;
     }
diff --git a/src/engine/imap-engine/replay-ops/imap-engine-list-email-by-sparse-id.vala 
b/src/engine/imap-engine/replay-ops/imap-engine-list-email-by-sparse-id.vala
index c7e42d4..1ab0eb4 100644
--- a/src/engine/imap-engine/replay-ops/imap-engine-list-email-by-sparse-id.vala
+++ b/src/engine/imap-engine/replay-ops/imap-engine-list-email-by-sparse-id.vala
@@ -8,9 +8,8 @@ private class Geary.ImapEngine.ListEmailBySparseID : Geary.ImapEngine.AbstractLi
     private Gee.HashSet<ImapDB.EmailIdentifier> ids = new Gee.HashSet<ImapDB.EmailIdentifier>();
     
     public ListEmailBySparseID(MinimalFolder owner, Gee.Collection<ImapDB.EmailIdentifier> ids,
-        Geary.Email.Field required_fields, Folder.ListFlags flags, Gee.List<Geary.Email>? accumulator,
-        EmailCallback cb, Cancellable? cancellable) {
-        base ("ListEmailBySparseID", owner, required_fields, flags, accumulator, cb, cancellable);
+        Geary.Email.Field required_fields, Folder.ListFlags flags, Cancellable? cancellable) {
+        base ("ListEmailBySparseID", owner, required_fields, flags, cancellable);
         
         this.ids.add_all(ids);
     }
@@ -62,20 +61,11 @@ private class Geary.ImapEngine.ListEmailBySparseID : Geary.ImapEngine.AbstractLi
             }
         }
         
-        if (fulfilled.size > 0) {
-            if (accumulator != null)
-                accumulator.add_all(fulfilled);
-            
-            if (cb != null)
-                cb(fulfilled, null);
-        }
+        if (fulfilled.size > 0)
+            accumulator.add_all(fulfilled);
         
-        if (flags.is_local_only() || get_unfulfilled_count() == 0) {
-            if (cb != null)
-                cb(null, null);
-            
+        if (flags.is_local_only() || get_unfulfilled_count() == 0)
             return ReplayOperation.Status.COMPLETED;
-        }
         
         return ReplayOperation.Status.CONTINUE;
     }
diff --git a/src/engine/imap-engine/replay-ops/imap-engine-server-search-email.vala 
b/src/engine/imap-engine/replay-ops/imap-engine-server-search-email.vala
index 5a96e0c..5b1443d 100644
--- a/src/engine/imap-engine/replay-ops/imap-engine-server-search-email.vala
+++ b/src/engine/imap-engine/replay-ops/imap-engine-server-search-email.vala
@@ -14,10 +14,10 @@ private class Geary.ImapEngine.ServerSearchEmail : Geary.ImapEngine.AbstractList
     private Imap.SearchCriteria criteria;
     
     public ServerSearchEmail(MinimalFolder owner, Imap.SearchCriteria criteria, Geary.Email.Field 
required_fields,
-        Gee.List<Geary.Email>? accumulator, Cancellable? cancellable) {
+        Cancellable? cancellable) {
         // OLDEST_TO_NEWEST used for vector expansion, if necessary
         base ("ServerSearchEmail", owner, required_fields, Geary.Folder.ListFlags.OLDEST_TO_NEWEST,
-            accumulator, null, cancellable);
+            cancellable);
         
         this.criteria = criteria;
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]