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



commit 4d18b7b75c4360010c98fa388a52b7c9eaafb786
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 1a9c31b8..fe373a00 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 {
@@ -367,7 +374,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) {
             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]