[geary/wip/725929-startup] Fetch incomplete locations in chunks



commit e5523cb28166621b1b7fa6028c20be5cfc0ecd2f
Author: Jim Nelson <jim yorba org>
Date:   Tue Aug 19 16:40:37 2014 -0700

    Fetch incomplete locations in chunks

 src/engine/imap-db/imap-db-folder.vala |   54 +++++++++++++++++++------------
 1 files changed, 33 insertions(+), 21 deletions(-)
---
diff --git a/src/engine/imap-db/imap-db-folder.vala b/src/engine/imap-db/imap-db-folder.vala
index 62a4179..02d73c0 100644
--- a/src/engine/imap-db/imap-db-folder.vala
+++ b/src/engine/imap-db/imap-db-folder.vala
@@ -2081,29 +2081,41 @@ private class Geary.ImapDB.Folder : BaseObject, Geary.ReferenceSemantics {
         if (locations == null || locations.size == 0)
             return;
         
-        StringBuilder sql = new StringBuilder("""
-            SELECT id FROM MessageTable WHERE id IN (
-        """);
-        bool first = true;
-        foreach (LocationIdentifier location_id in locations) {
-            if (!first)
-                sql.append(",");
-            
-            sql.append(location_id.message_id.to_string());
-            first = false;
-        }
-        sql.append(") AND fields <> ?");
-        
-        Db.Statement stmt = cx.prepare(sql.str);
-        stmt.bind_int(0, Geary.Email.Field.ALL);
-        
-        Db.Result results = stmt.exec(cancellable);
-        
+        // fetch incomplete locations in chunks
         Gee.HashSet<int64?> incomplete_locations = new Gee.HashSet<int64?>(Collection.int64_hash_func,
             Collection.int64_equal_func);
-        while (!results.finished) {
-            incomplete_locations.add(results.int64_at(0));
-            results.next(cancellable);
+        int start = 0;
+        for (;;) {
+            if (start >= locations.size)
+                break;
+            
+            int end = (start + LIST_EMAIL_FIELDS_CHUNK_COUNT).clamp(0, locations.size);
+            Gee.List<LocationIdentifier> slice = locations.slice(start, end);
+            
+            StringBuilder sql = new StringBuilder("""
+                SELECT id FROM MessageTable WHERE id IN (
+            """);
+            bool first = true;
+            foreach (LocationIdentifier location_id in slice) {
+                if (!first)
+                    sql.append(",");
+                
+                sql.append(location_id.message_id.to_string());
+                first = false;
+            }
+            sql.append(") AND fields <> ?");
+            
+            Db.Statement stmt = cx.prepare(sql.str);
+            stmt.bind_int(0, Geary.Email.Field.ALL);
+            
+            Db.Result results = stmt.exec(cancellable);
+            
+            while (!results.finished) {
+                incomplete_locations.add(results.int64_at(0));
+                results.next(cancellable);
+            }
+            
+            start = end;
         }
         
         if (incomplete_locations.size == 0) {


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