[geary/wip/unread-status-714865: 8/10] Prevent recursion



commit 585436ba7bc13b8a4896ced2c50e9a00f4d89973
Author: Charles Lindsay <chaz yorba org>
Date:   Thu Feb 20 16:51:34 2014 -0800

    Prevent recursion

 .../imap-engine/imap-engine-generic-account.vala   |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
---
diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala 
b/src/engine/imap-engine/imap-engine-generic-account.vala
index 8ab2628..4b1388d 100644
--- a/src/engine/imap-engine/imap-engine-generic-account.vala
+++ b/src/engine/imap-engine/imap-engine-generic-account.vala
@@ -19,6 +19,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount {
     private Gee.HashMap<FolderPath, Folder> local_only = new Gee.HashMap<FolderPath, Folder>();
     private Gee.HashMap<FolderPath, uint> refresh_unseen_timeout_ids
         = new Gee.HashMap<FolderPath, uint>();
+    private Gee.HashSet<Geary.Folder> in_refresh_unseen = new Gee.HashSet<Geary.Folder>();
     private uint refresh_folder_timeout_id = 0;
     private bool in_refresh_enumerate = false;
     private Cancellable refresh_cancellable = new Cancellable();
@@ -297,7 +298,9 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount {
     }
     
     private bool on_refresh_unseen(Geary.Folder folder) {
-        // TODO: prevent recursion?
+        // If we're in the process already, reschedule for later.
+        if (in_refresh_unseen.contains(folder))
+            return true;
         
         // TODO: cancellable?
         refresh_unseen_async.begin(folder, null, on_refresh_unseen_completed);
@@ -315,6 +318,8 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount {
     }
     
     private async void refresh_unseen_async(Geary.Folder folder, Cancellable? cancellable) throws Error {
+        in_refresh_unseen.add(folder);
+        
         debug("Refreshing unseen counts for %s", folder.to_string());
         
         int unseen_count = yield remote.fetch_unseen_count_async(folder.path, cancellable);
@@ -323,6 +328,8 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount {
         // TODO: nothing to refresh if that fetch just hit the network.
         remote_folder.properties.set_status_unseen(unseen_count);
         yield local.update_folder_status_async(remote_folder, false, cancellable);
+        
+        in_refresh_unseen.remove(folder);
     }
     
     private void reschedule_folder_refresh(bool immediate) {


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