[PATCH 11/14] lib: Report progress for combined upgrade operation
authorAustin Clements <amdragon@MIT.EDU>
Sun, 27 Jul 2014 03:52:50 +0000 (23:52 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:03:53 +0000 (10:03 -0800)
aa/a0ce93eda940aefa03d0538f50f290f048e5da [new file with mode: 0644]

diff --git a/aa/a0ce93eda940aefa03d0538f50f290f048e5da b/aa/a0ce93eda940aefa03d0538f50f290f048e5da
new file mode 100644 (file)
index 0000000..fa71537
--- /dev/null
@@ -0,0 +1,131 @@
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 14494431FBC\r
+       for <notmuch@notmuchmail.org>; Sat, 26 Jul 2014 20:53:36 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id tFWTaWQdFp7I for <notmuch@notmuchmail.org>;\r
+       Sat, 26 Jul 2014 20:53:30 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-8.mit.edu (dmz-mailsec-scanner-8.mit.edu\r
+       [18.7.68.37])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 00D35431FD0\r
+       for <notmuch@notmuchmail.org>; Sat, 26 Jul 2014 20:53:08 -0700 (PDT)\r
+X-AuditID: 12074425-f79766d000006da8-c8-53d477a26983\r
+Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
+       (using TLS with cipher AES256-SHA (256/256 bits))\r
+       (Client did not present a certificate)\r
+       by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 21.5E.28072.2A774D35; Sat, 26 Jul 2014 23:53:06 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+       by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id s6R3r2Pf008822; \r
+       Sat, 26 Jul 2014 23:53:02 -0400\r
+Received: from drake.dyndns.org\r
+       (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+       [216.15.114.40]) (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s6R3r0NC016408\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sat, 26 Jul 2014 23:53:01 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1XBFW8-00051b-F2; Sat, 26 Jul 2014 23:53:00 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 11/14] lib: Report progress for combined upgrade operation\r
+Date: Sat, 26 Jul 2014 23:52:50 -0400\r
+Message-Id: <1406433173-19169-12-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 2.0.0\r
+In-Reply-To: <1406433173-19169-1-git-send-email-amdragon@mit.edu>\r
+References: <1406433173-19169-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixCmqrLuo/Eqwwc2N1hbXb85kdmD0eLbq\r
+       FnMAYxSXTUpqTmZZapG+XQJXxrZZn9gL7vNWHN90hrmB8T9XFyMnh4SAicTKz7fZIWwxiQv3\r
+       1rN1MXJxCAnMZpJ4cu0pM4SzkVHi6fSrrBDOHSaJRXu7oMrmMkq8+vqVFaSfTUBDYtv+5Ywg\r
+       toiAtMTOu7OB4hwczAJqEn+6VEBMYQEviV+tFiAVLAKqEg+mnWQBsXkFHCXmrL7CAnGFnETD\r
+       jU9sIDYnUPz4sxNsIK1CAg4Sty4lTmDkX8DIsIpRNiW3Sjc3MTOnODVZtzg5MS8vtUjXQi83\r
+       s0QvNaV0EyMoZNhdVHcwTjikdIhRgINRiYdXgOVKsBBrYllxZe4hRkkOJiVR3v1mQCG+pPyU\r
+       yozE4oz4otKc1OJDjBIczEoivELFQDnelMTKqtSifJiUNAeLkjjvW2urYCGB9MSS1OzU1ILU\r
+       IpisDAeHkgTv11KgRsGi1PTUirTMnBKENBMHJ8hwHqDhG0BqeIsLEnOLM9Mh8qcYFaXEeX+B\r
+       JARAEhmleXC9sJh+xSgO9IowL2sZUBUPMB3Adb8CGswENJjF/zLI4JJEhJRUA2Mytz/POxbd\r
+       s4GS2v/jbXX/7mXm5TnazRRR4r2YQSHv8AUlZpkbn3z71oheu3TpwXqT7OeWnuavr25cIc41\r
+       RfnXs0ubeCd9MPXeedho/+tdnBOjN6j37fI8F+DHEpS8+sVm1cP6PEtDZcQnmX3Z1FP/wv01\r
+       v/WXBYWR6152TJ533v7Dh8OxptuVWIozEg21mIuKEwHpKmJ1xAIAAA==\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 27 Jul 2014 03:53:36 -0000\r
+\r
+Previously, some parts of upgrade didn't report progress and for\r
+others it was possible for the progress meter to restart at 0 part way\r
+through the upgrade because each stage was reported separately.\r
+\r
+Fix this by computing the total amount of work that needs to be done\r
+up-front and updating completed work monotonically.\r
+---\r
+ lib/database.cc | 17 +++++++++++++++--\r
+ 1 file changed, 15 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 155cbac..a93281c 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -1240,6 +1240,19 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
+       timer_is_active = TRUE;\r
+     }\r
\r
++    /* Figure out how much total work we need to do. */\r
++    if (new_features &\r
++      (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER)) {\r
++      notmuch_query_t *query = notmuch_query_create (notmuch, "");\r
++      total += notmuch_query_count_messages (query);\r
++      notmuch_query_destroy (query);\r
++    }\r
++    if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) {\r
++      t_end = db->allterms_end ("XTIMESTAMP");\r
++      for (t = db->allterms_begin ("XTIMESTAMP"); t != t_end; t++)\r
++          ++total;\r
++    }\r
++\r
+     /* Perform the upgrade in a transaction. */\r
+     db->begin_transaction (true);\r
\r
+@@ -1251,8 +1264,6 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
+       notmuch_message_t *message;\r
+       char *filename;\r
\r
+-      total = notmuch_query_count_messages (query);\r
+-\r
+       for (messages = notmuch_query_search_messages (query);\r
+            notmuch_messages_valid (messages);\r
+            notmuch_messages_move_to_next (messages))\r
+@@ -1336,6 +1347,8 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
\r
+               db->delete_document (*p);\r
+           }\r
++\r
++          ++count;\r
+       }\r
+     }\r
\r
+-- \r
+2.0.0\r
+\r