[PATCH v4 08/11] lib: Report progress for combined upgrade operation
authorAustin Clements <amdragon@mit.edu>
Mon, 25 Aug 2014 17:26:06 +0000 (13:26 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:04:19 +0000 (10:04 -0800)
ed/20c54d6a766e0be5512774049565500cfff3a1 [new file with mode: 0644]

diff --git a/ed/20c54d6a766e0be5512774049565500cfff3a1 b/ed/20c54d6a766e0be5512774049565500cfff3a1
new file mode 100644 (file)
index 0000000..95c2f9d
--- /dev/null
@@ -0,0 +1,130 @@
+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 0F922431FC2\r
+       for <notmuch@notmuchmail.org>; Mon, 25 Aug 2014 10:26:25 -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 DI5oy0jYzQOk for <notmuch@notmuchmail.org>;\r
+       Mon, 25 Aug 2014 10:26:17 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-6.mit.edu (dmz-mailsec-scanner-6.mit.edu\r
+       [18.7.68.35])\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 905E4431FAF\r
+       for <notmuch@notmuchmail.org>; Mon, 25 Aug 2014 10:26:17 -0700 (PDT)\r
+X-AuditID: 12074423-f799d6d00000337c-76-53fb71b73adf\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-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id CA.A0.13180.7B17BF35; Mon, 25 Aug 2014 13:26:15 -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 s7PHQE5P007796; \r
+       Mon, 25 Aug 2014 13:26:14 -0400\r
+Received: from drake.dyndns.org (31-35-14.wireless.csail.mit.edu\r
+       [128.31.35.14]) (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 s7PHQCVJ029619\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Mon, 25 Aug 2014 13:26:13 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1XLy20-0003je-1S; Mon, 25 Aug 2014 13:26:12 -0400\r
+From: Austin Clements <amdragon@mit.edu>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v4 08/11] lib: Report progress for combined upgrade operation\r
+Date: Mon, 25 Aug 2014 13:26:06 -0400\r
+Message-Id: <1408987569-14146-9-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 2.0.0\r
+In-Reply-To: <1408987569-14146-1-git-send-email-amdragon@mit.edu>\r
+References: <1408987569-14146-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFjrGIsWRmVeSWpSXmKPExsUixCmqrLu98HewwfwH0hY3WrsZLZqmO1tc\r
+       vzmT2YHZ49b91+wez1bdYvbYcug9cwBzFJdNSmpOZllqkb5dAlfG/sUPGAvu81a8+TaTrYHx\r
+       P1cXIyeHhICJxJXvW9ggbDGJC/fWA9lcHEICs5kklvV/YIRwNjJK7D/0mBXCOcYksXHpVXYI\r
+       Zy6jxMXpjUwg/WwCGhK/by0Gs0UEpCV23p3NCmIzC3hJLLvQD2YLC/hKXHrUwgxiswioSjzc\r
+       vRfI5uDgFXCQuHDYHeIMOYmGG5/ATuIUcJSYvnA22EghoJLvl88zT2DkX8DIsIpRNiW3Sjc3\r
+       MTOnODVZtzg5MS8vtUjXTC83s0QvNaV0EyMouNhdlHcw/jmodIhRgINRiYf3RvzvYCHWxLLi\r
+       ytxDjJIcTEqivNPygUJ8SfkplRmJxRnxRaU5qcWHGCU4mJVEeJtBcrwpiZVVqUX5MClpDhYl\r
+       cd631lbBQgLpiSWp2ampBalFMFkZDg4lCd7cAqBGwaLU9NSKtMycEoQ0EwcnyHAeoOHxIDW8\r
+       xQWJucWZ6RD5U4yKUuK8a0G2CoAkMkrz4Hph0f+KURzoFWHeoyDtPMDEAdf9CmgwE9Bg056f\r
+       IINLEhFSUg2MzmsaI25Yaf9zdHuS5KyddTPjWobcrVMrtq925Kl5s+n4Y/45EYvPiB7cHCJ8\r
+       QZjr46LrpTEKx8JtonXyyvxrghdIXbtolLb6sbnfdq55R0rP2LztMmDxn9GSd/jpQsO812sT\r
+       H1/Y2RRf9G/136cLBN/a+XcFPE+Qmr9b8j63oXxN5MVdcUlCSizFGYmGWsxFxYkAbzTtD9kC        AAA=\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: Mon, 25 Aug 2014 17:26:25 -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 6a7ce29..53397bb 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -1241,6 +1241,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
+@@ -1256,8 +1269,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
+@@ -1340,6 +1351,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