[geary/wip/713530-background-sync: 5/9] Ensure initial sync has an accurate idea of mailbox message count.



commit 7aedb494b5f8cfd60e774d831cdee8c8391c8cb0
Author: Michael James Gratton <mike vee net>
Date:   Fri Dec 1 11:55:52 2017 +1100

    Ensure initial sync has an accurate idea of mailbox message count.
    
    * src/engine/imap-engine/imap-engine-account-synchronizer.vala
      (AccountSynchronizer): Use MinimalFolder.get_remote_counts rather than
      properties.email total since that could be updated only from the local
      folder initially.

 .../imap-engine-account-synchronizer.vala          |   25 ++++++++++++--------
 1 files changed, 15 insertions(+), 10 deletions(-)
---
diff --git a/src/engine/imap-engine/imap-engine-account-synchronizer.vala 
b/src/engine/imap-engine/imap-engine-account-synchronizer.vala
index 3494b21..0633c6e 100644
--- a/src/engine/imap-engine/imap-engine-account-synchronizer.vala
+++ b/src/engine/imap-engine/imap-engine-account-synchronizer.vala
@@ -272,6 +272,8 @@ private class Geary.ImapEngine.AccountSynchronizer : Geary.BaseObject {
             Logging.Flag.PERIODIC, "Background sync'ing %s", folder.to_string()
         );
 
+        int remote_count = folder.get_remote_counts(null, null);
+
         // get oldest local email and its time, as well as number of messages in local store
         DateTime? oldest_local = null;
         Geary.EmailIdentifier? oldest_local_id = null;
@@ -301,21 +303,21 @@ private class Geary.ImapEngine.AccountSynchronizer : Geary.BaseObject {
                 if (oldest_local.compare(epoch) < 0) {
                     // Oldest local email before epoch, don't sync from network
                     do_sync = false;
-                } else if (folder.properties.email_total == local_count) {
+                } else if (local_count >= remote_count) {
                     // Local earliest email is after epoch, but there's nothing before it
                     do_sync = false;
                 } else {
                     Logging.debug(
                         Logging.Flag.PERIODIC,
-                        "Oldest local email in %s not old enough (%s vs. %s), email_total=%d vs. 
local_count=%d, synchronizing...",
+                        "Oldest local email in %s not old enough (%s vs. %s), local_count=%d vs. 
remote_total=%d, synchronizing...",
                         folder.to_string(),
                         oldest_local.to_string(),
                         epoch.to_string(),
-                        folder.properties.email_total,
-                        local_count
+                        local_count,
+                        remote_count
                     );
                 }
-            } else if (folder.properties.email_total == 0) {
+            } else if (remote_count == 0) {
                 // no local messages, no remote messages -- this is as good as having everything up
                 // to the epoch
                 do_sync = false;
@@ -375,11 +377,14 @@ private class Geary.ImapEngine.AccountSynchronizer : Geary.BaseObject {
                 // no need to keep searching once this happens
                 int local_count = yield 
folder.local_folder.get_email_count_async(ImapDB.Folder.ListFlags.NONE,
                     cancellable);
-                if (local_count >= folder.properties.email_total) {
+                int remote_count = folder.get_remote_counts(null, null);
+                if (local_count >= remote_count) {
                     Logging.debug(
                         Logging.Flag.PERIODIC,
-                        "Total vector normalization for %s: %d/%d emails", folder.to_string(), local_count,
-                        folder.properties.email_total
+                        "Final vector normalization for %s: %d/%d emails",
+                        folder.to_string(),
+                        local_count,
+                        remote_count
                     );
                     break;
                 }
@@ -394,7 +399,7 @@ private class Geary.ImapEngine.AccountSynchronizer : Geary.BaseObject {
                         max_epoch.to_string(),
                         folder.to_string(),
                         local_count,
-                        folder.properties.email_total
+                        remote_count
                     );
 
                     yield folder.list_email_by_id_async(null, 1, Geary.Email.Field.NONE,
@@ -410,7 +415,7 @@ private class Geary.ImapEngine.AccountSynchronizer : Geary.BaseObject {
                         folder.to_string(),
                         current_epoch.to_string(),
                         local_count,
-                        folder.properties.email_total
+                        remote_count
                     );
                     Geary.EmailIdentifier? earliest_span_id = yield 
folder.find_earliest_email_async(current_epoch,
                         oldest_local_id, cancellable);


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