[geary/wip/713150-conversations: 9/20] Remove ConversationMonitor reseed operation



commit c188f4d6684629af952765689261ec181d56db1c
Author: Jim Nelson <jim yorba org>
Date:   Fri Mar 13 15:42:32 2015 -0700

    Remove ConversationMonitor reseed operation
    
    No longer needed, only introduced extra complication to an already-
    complicated class.  Also, better checking for the presence of
    scrollbars in the conversation list view.

 src/CMakeLists.txt                                 |    1 -
 src/client/application/geary-controller.vala       |   31 ++++++++---
 src/engine/app/app-conversation-monitor.vala       |   58 ++++----------------
 .../conversation-monitor/app-reseed-operation.vala |   18 ------
 4 files changed, 34 insertions(+), 74 deletions(-)
---
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c145f89..ec586c9 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -58,7 +58,6 @@ engine/app/conversation-monitor/app-external-remove-operation.vala
 engine/app/conversation-monitor/app-fill-window-operation.vala
 engine/app/conversation-monitor/app-local-load-operation.vala
 engine/app/conversation-monitor/app-remove-operation.vala
-engine/app/conversation-monitor/app-reseed-operation.vala
 engine/app/conversation-monitor/app-terminate-operation.vala
 
 engine/app/email-store/app-async-folder-operation.vala
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 63a518c..85a37bc 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -131,6 +131,7 @@ public class GearyController : Geary.BaseObject {
     private Geary.Nonblocking.Mutex untrusted_host_prompt_mutex = new Geary.Nonblocking.Mutex();
     private Gee.HashSet<Geary.Endpoint> validating_endpoints = new Gee.HashSet<Geary.Endpoint>();
     private Geary.Revokable? revokable = null;
+    private uint scrollbar_check_id = 0;
     
     // List of windows we're waiting to close before Geary closes.
     private Gee.List<ComposerWidget> waiting_to_close = new Gee.ArrayList<ComposerWidget>();
@@ -1452,8 +1453,7 @@ public class GearyController : Geary.BaseObject {
         }
         
         current_conversations.scan_error.connect(on_scan_error);
-        current_conversations.seed_completed.connect(on_seed_completed);
-        current_conversations.seed_completed.connect(on_conversation_count_changed);
+        current_conversations.scan_completed.connect(on_scan_completed);
         current_conversations.scan_completed.connect(on_conversation_count_changed);
         current_conversations.conversations_added.connect(on_conversation_count_changed);
         current_conversations.conversation_removed.connect(on_conversation_count_changed);
@@ -1471,13 +1471,30 @@ public class GearyController : Geary.BaseObject {
         debug("Scan error: %s", err.message);
     }
     
-    private void on_seed_completed() {
+    private void on_scan_completed() {
+        if (scrollbar_check_id != 0)
+            Source.remove(scrollbar_check_id);
+        
+        // Check for scrollbar after low idle, to give repaint and resize a chance to complete
+        scrollbar_check_id = Idle.add(check_for_enough_conversations, Priority.LOW);
+    }
+    
+    private bool check_for_enough_conversations() {
+        // all code paths lead to this SourceFunc being removed when completed
+        scrollbar_check_id = 0;
+        
         // Done scanning.  Check if we have enough messages to fill the conversation list; if not,
         // trigger a load_more();
-        if (!main_window.conversation_list_has_scrollbar()) {
-            debug("Not enough messages, loading more for folder %s", current_folder.to_string());
-            on_load_more();
-        }
+        if (main_window.conversation_list_has_scrollbar())
+            return false;
+        
+        debug("Not enough conversations (%d/%d) for scrollbars, loading more from folder %s",
+            current_conversations.get_conversation_count(), current_conversations.min_window_count,
+            current_folder.to_string());
+        
+        on_load_more();
+        
+        return false;
     }
     
     private void on_conversation_count_changed() {
diff --git a/src/engine/app/app-conversation-monitor.vala b/src/engine/app/app-conversation-monitor.vala
index ec0278f..c708e65 100644
--- a/src/engine/app/app-conversation-monitor.vala
+++ b/src/engine/app/app-conversation-monitor.vala
@@ -92,7 +92,6 @@ public class Geary.App.ConversationMonitor : BaseObject {
     private Geary.Email.Field required_fields;
     private Geary.Folder.OpenFlags open_flags;
     private Cancellable? cancellable_monitor = null;
-    private bool reseed_notified = false;
     private int _min_window_count = 0;
     private ConversationOperationQueue operation_queue = new ConversationOperationQueue();
     
@@ -157,14 +156,6 @@ public class Geary.App.ConversationMonitor : BaseObject {
     }
     
     /**
-     * "seed-completed" is fired when the folder has opened and email has been populated.
-     */
-    public virtual signal void seed_completed() {
-        Logging.debug(Logging.Flag.CONVERSATIONS, "[%s] ConversationMonitor::seed_completed",
-            folder.to_string());
-    }
-    
-    /**
      * "conversations-added" indicates that one or more new Conversations have been detected while
      * processing email, either due to a user-initiated load request or due to monitoring.
      */
@@ -271,10 +262,6 @@ public class Geary.App.ConversationMonitor : BaseObject {
         scan_completed();
     }
     
-    protected virtual void notify_seed_completed() {
-        seed_completed();
-    }
-    
     protected virtual void notify_conversations_added(Gee.Collection<Conversation> conversations) {
         conversations_added(conversations);
     }
@@ -329,15 +316,9 @@ public class Geary.App.ConversationMonitor : BaseObject {
             yield operation_queue.stop_processing_async(cancellable_monitor);
         operation_queue.clear();
         
-        bool reseed_now = (folder.get_open_state() != Geary.Folder.OpenState.CLOSED);
-        
-        // Add the necessary initial operations ahead of anything the folder
-        // might add as it opens.
+        // Add the necessary initial operations ahead of anything the Folder might notify us of
+        // (additions, removals, etc.)
         operation_queue.add(new LocalLoadOperation(this));
-        // if already opened, go ahead and do a full load now from remote and local; otherwise,
-        // the reseed has to wait until the folder's remote is opened (handled in on_folder_opened)
-        if (reseed_now)
-            operation_queue.add(new ReseedOperation(this, "already opened"));
         operation_queue.add(new FillWindowOperation(this, false));
         
         connect_to_folder();
@@ -353,7 +334,6 @@ public class Geary.App.ConversationMonitor : BaseObject {
         }
         
         notify_monitoring_started();
-        reseed_notified = false;
         
         // Process operations in the background.
         operation_queue.run_process_async.begin();
@@ -366,6 +346,8 @@ public class Geary.App.ConversationMonitor : BaseObject {
         yield load_by_id_async(null, min_window_count, required_fields, Folder.ListFlags.LOCAL_ONLY,
             cancellable_monitor);
         debug("ConversationMonitor seeded for %s", folder.to_string());
+        
+        operation_queue.add(new FillWindowOperation(this, false));
     }
     
     /**
@@ -660,18 +642,19 @@ public class Geary.App.ConversationMonitor : BaseObject {
     }
     
     private bool is_folder_external_conversation_source(Folder folder) {
-        return !folder.path.equal_to(this.folder.path)
-            && !folder.properties.is_local_only
-            && !folder.properties.is_virtual;
+        return !folder.properties.is_local_only && !folder.properties.is_virtual;
     }
     
     private void on_account_email_added(Folder folder, Gee.Collection<EmailIdentifier> added_ids) {
+        // ignore virtual/local-only folders but add new messages locally completed in this Folder
         if (is_folder_external_conversation_source(folder))
             operation_queue.add(new ExternalAppendOperation(this, folder, added_ids));
     }
     
     private void on_account_email_removed(Folder folder, Gee.Collection<EmailIdentifier> removed_ids) {
-        if (!is_folder_external_conversation_source(folder))
+        // ignore virtual/local-only Folders as well as removals from this Folder, which we're
+        // tracking
+        if (!is_folder_external_conversation_source(folder) || folder.path.equal_to(this.folder.path))
             return;
         
         operation_queue.add(new ExternalRemoveOperation(this, folder, removed_ids));
@@ -783,31 +766,10 @@ public class Geary.App.ConversationMonitor : BaseObject {
         return earliest_id;
     }
     
-    internal async void reseed_async(string why) {
-        Geary.EmailIdentifier? earliest_id = yield get_lowest_email_id_async(null);
-        if (earliest_id != null) {
-            debug("ConversationMonitor (%s) reseeding starting from Email ID %s on opened %s", why,
-                earliest_id.to_string(), folder.to_string());
-            yield load_by_id_async(earliest_id, int.MAX, Email.Field.NONE,
-                Geary.Folder.ListFlags.OLDEST_TO_NEWEST | Geary.Folder.ListFlags.INCLUDING_ID,
-                cancellable_monitor);
-        } else {
-            debug("ConversationMonitor (%s) reseeding latest %d emails on opened %s", why,
-                min_window_count, folder.to_string());
-            yield load_by_id_async(null, min_window_count, Email.Field.NONE, Geary.Folder.ListFlags.NONE,
-                cancellable_monitor);
-        }
-        
-        if (!reseed_notified) {
-            reseed_notified = true;
-            notify_seed_completed();
-        }
-    }
-    
     private void on_folder_opened(Geary.Folder.OpenState state, int count) {
         // once remote is open, reseed with messages from the earliest ID to the latest
         if (state == Geary.Folder.OpenState.BOTH || state == Geary.Folder.OpenState.REMOTE)
-            operation_queue.add(new ReseedOperation(this, state.to_string()));
+            operation_queue.add(new FillWindowOperation(this, false));
     }
     
     /**


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