[geary] Improved search indexing progress indicator usage: Bug #713153



commit 0004080f66a994809cafa6a31f03830f1921817a
Author: Jim Nelson <jim yorba org>
Date:   Thu Oct 23 17:24:32 2014 -0700

    Improved search indexing progress indicator usage: Bug #713153
    
    This change does two things: (a) Only activate the search index
    progress monitor if indexing has actually started (i.e. doesn't
    display if no work is to be done), and (b) better estimates the amount
    of work to be performed so the progress bar doesn't "jump" at the very
    end.

 src/engine/imap-db/imap-db-account.vala |   26 +++++++++++++++++---------
 1 files changed, 17 insertions(+), 9 deletions(-)
---
diff --git a/src/engine/imap-db/imap-db-account.vala b/src/engine/imap-db/imap-db-account.vala
index f727b5d..c4a370e 100644
--- a/src/engine/imap-db/imap-db-account.vala
+++ b/src/engine/imap-db/imap-db-account.vala
@@ -1104,10 +1104,6 @@ private class Geary.ImapDB.Account : BaseObject {
     private async void populate_search_table_async(Cancellable? cancellable) {
         debug("%s: Populating search table", account_information.email);
         try {
-            int total = yield get_email_count_async(cancellable);
-            search_index_monitor.set_interval(0, total);
-            search_index_monitor.notify_start();
-            
             while (!yield populate_search_table_batch_async(50, cancellable)) {
                 // With multiple accounts, meaning multiple background threads
                 // doing such CPU- and disk-heavy work, this process can cause
@@ -1143,7 +1139,7 @@ private class Geary.ImapDB.Account : BaseObject {
         debug("%s: Searching for up to %d missing indexed messages...", account_information.email,
             limit);
         
-        int count = 0;
+        int count = 0, total_unindexed = 0;
         yield db.exec_transaction_async(Db.TransactionType.RW, (cx, cancellable) => {
             // Embedding a SELECT within a SELECT is painfully slow with SQLite, so manually
             // perform the operation
@@ -1162,6 +1158,11 @@ private class Geary.ImapDB.Account : BaseObject {
             """);
             Gee.HashSet<int64?> message_ids = do_build_rowid_set(stmt.exec(cancellable), cancellable);
             
+            // guesstimate at the number that need to be indexed ... technically if this is zero then
+            // we're done, but for safety allow the chaffing to go through, in case there are search
+            // rows that do not correspond to message rows (which is bad but not fatal)
+            total_unindexed = (message_ids.size - search_ids.size).clamp(0, int.MAX);
+            
             // chaff out any MessageTable entries not present in the MessageSearchTable ... since
             // we're given a limit, stuff messages req'ing search into separate set and stop when limit
             // reached
@@ -1204,10 +1205,17 @@ private class Geary.ImapDB.Account : BaseObject {
             return Db.TransactionOutcome.DONE;
         }, cancellable);
         
-        search_index_monitor.increment(count);
-        
-        if (count > 0)
-            debug("%s: Found %d/%d missing indexed messages...", account_information.email, count, limit);
+        if (count > 0) {
+            debug("%s: Found %d/%d missing indexed messages, %d remaining...",
+                account_information.email, count, limit, total_unindexed);
+            
+            if (!search_index_monitor.is_in_progress) {
+                search_index_monitor.set_interval(0, total_unindexed);
+                search_index_monitor.notify_start();
+            }
+            
+            search_index_monitor.increment(count);
+        }
         
         return (count < limit);
     }


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