[geary/wip/search-fixes: 10/14] Only insert email into the conversation monitor when needed



commit d217e57f92fd184473b3d4cb25a3d0bc7b62551a
Author: Michael Gratton <mike vee net>
Date:   Tue Aug 6 21:18:10 2019 +1000

    Only insert email into the conversation monitor when needed
    
    In InsertOperation, check that more are needed and if not, only insert
    if above the last email in the folder window, so we don't blow out the
    window size when large inserts coming in (e.g. from the search folder).

 src/engine/app/app-conversation-monitor.vala       |  9 +++++-
 .../conversation-monitor/app-insert-operation.vala | 34 +++++++++++++---------
 2 files changed, 28 insertions(+), 15 deletions(-)
---
diff --git a/src/engine/app/app-conversation-monitor.vala b/src/engine/app/app-conversation-monitor.vala
index c7ceed4d..ba0d603b 100644
--- a/src/engine/app/app-conversation-monitor.vala
+++ b/src/engine/app/app-conversation-monitor.vala
@@ -85,6 +85,13 @@ public class Geary.App.ConversationMonitor : BaseObject {
     /** Determines if this monitor is monitoring the base folder. */
     public bool is_monitoring { get; private set; default = false; }
 
+    /** Determines if more conversations should be loaded. */
+    public bool should_load_more {
+        get {
+            return (this.conversations.size < this.min_window_count);
+        }
+    }
+
     /** Determines if more conversations can be loaded. */
     public bool can_load_more {
         get {
@@ -364,7 +371,7 @@ public class Geary.App.ConversationMonitor : BaseObject {
     internal void check_window_count() {
         if (this.is_monitoring &&
             this.can_load_more &&
-            this.conversations.size < this.min_window_count) {
+            this.should_load_more) {
             GLib.Idle.add(
                 () => {
                     this.queue.add(new FillWindowOperation(this));
diff --git a/src/engine/app/conversation-monitor/app-insert-operation.vala 
b/src/engine/app/conversation-monitor/app-insert-operation.vala
index 64475a86..3ee8fac5 100644
--- a/src/engine/app/conversation-monitor/app-insert-operation.vala
+++ b/src/engine/app/conversation-monitor/app-insert-operation.vala
@@ -1,9 +1,8 @@
 /*
  * Copyright 2016 Software Freedom Conservancy Inc.
- * Copyright 2019 Michael Gratton <mike vee net>
  *
  * This software is licensed under the GNU Lesser General Public License
- * (version 2.1 or later). See the COPYING file in this distribution.
+ * (version 2.1 or later).  See the COPYING file in this distribution.
  */
 
 /**
@@ -19,23 +18,30 @@ private class Geary.App.InsertOperation : BatchOperation<EmailIdentifier> {
 
     public override async void execute_batch(Gee.Collection<EmailIdentifier> batch)
         throws GLib.Error {
+        // Insert messages that are older than the current window
+        // eldest only if the window is smaller than it could be, to
+        // avoid involuntarily growing the window larger more than it
+        // needs to be.
+        bool needs_more = this.monitor.should_load_more;
         Geary.EmailIdentifier? lowest = this.monitor.window_lowest;
-        Gee.Collection<EmailIdentifier>? to_insert = null;
         if (lowest != null) {
-            to_insert = new Gee.LinkedList<EmailIdentifier>();
-            foreach (EmailIdentifier inserted in batch) {
-                if (lowest.natural_sort_comparator(inserted) < 0) {
-                    to_insert.add(inserted);
+            Gee.Iterator<EmailIdentifier> iter = batch.iterator();
+            while (iter.next()) {
+                EmailIdentifier inserted = iter.get();
+                if (!needs_more && lowest.natural_sort_comparator(inserted) > 0) {
+                    iter.remove();
                 }
             }
-        } else {
-            to_insert = batch;
         }
 
-        debug("Inserting %d of %d messages into %s",
-              to_insert.size,
-              batch.size,
-              this.monitor.base_folder.to_string());
-        yield this.monitor.load_by_sparse_id(to_insert);
+        if (!batch.is_empty) {
+            debug("Inserting %u messages into %s",
+                  batch.size,
+                  this.monitor.base_folder.to_string());
+            yield this.monitor.load_by_sparse_id(batch);
+        } else {
+            debug("Inserting no messages into %s, none needed",
+                  this.monitor.base_folder.to_string());
+        }
     }
 }


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