[PATCH v3] emacs: Call "notmuch tag" once when applying tag changes to a thread.
authorDavid Edmondson <dme@dme.org>
Wed, 8 Feb 2012 08:36:09 +0000 (08:36 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:44:16 +0000 (09:44 -0800)
af/f39bff6c4dd49102435f5f0a9827d9962d1893 [new file with mode: 0644]

diff --git a/af/f39bff6c4dd49102435f5f0a9827d9962d1893 b/af/f39bff6c4dd49102435f5f0a9827d9962d1893
new file mode 100644 (file)
index 0000000..2c2c2d7
--- /dev/null
@@ -0,0 +1,119 @@
+Return-Path: <dme@dme.org>\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 8F640431FAF\r
+       for <notmuch@notmuchmail.org>; Wed,  8 Feb 2012 00:36:16 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 E9qnuFwuzniN for <notmuch@notmuchmail.org>;\r
+       Wed,  8 Feb 2012 00:36:16 -0800 (PST)\r
+Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
+       [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id CC641431FAE\r
+       for <notmuch@notmuchmail.org>; Wed,  8 Feb 2012 00:36:15 -0800 (PST)\r
+Received: by werp13 with SMTP id p13so226628wer.26\r
+       for <notmuch@notmuchmail.org>; Wed, 08 Feb 2012 00:36:14 -0800 (PST)\r
+MIME-Version: 1.0\r
+Received: by 10.180.85.105 with SMTP id g9mr24928515wiz.12.1328690174638;\r
+       Wed, 08 Feb 2012 00:36:14 -0800 (PST)\r
+Received: from hotblack-desiato.hh.sledj.net\r
+       (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25])\r
+       by mx.google.com with ESMTPS id y6sm25966710wix.10.2012.02.08.00.36.12\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Wed, 08 Feb 2012 00:36:13 -0800 (PST)\r
+Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
+       id 9225EA168E; Wed,  8 Feb 2012 08:36:11 +0000 (GMT)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3] emacs: Call "notmuch tag" once when applying tag changes\r
+       to a thread.\r
+Date: Wed,  8 Feb 2012 08:36:09 +0000\r
+Message-Id: <1328690169-6991-1-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 1.7.8.3\r
+In-Reply-To: <1328632303-31877-1-git-send-email-jani@nikula.org>\r
+References: <1328632303-31877-1-git-send-email-jani@nikula.org>\r
+X-Gm-Message-State:\r
+ ALoCoQnCh8lbUtOeBUbse3rVYDu+oSLvJj0aE8xRKOO12UAF+M1l7+W9WI7tk7gQLFJbLiM/TMRq\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: Wed, 08 Feb 2012 08:36:16 -0000\r
+\r
+Optimize thread tagging by combining all the tagging operations to a\r
+single "notmuch tag" call.\r
+\r
+For threads in the order of tens or a hundred inbox tagged messages,\r
+this gives a noticeable speedup. On two different machines, archiving\r
+a thread of about 50 inbox tagged messages goes down from 10+ seconds\r
+to about 0.5 seconds.\r
+\r
+The bottleneck is not within emacs; the same behaviour can be observed\r
+in the CLI. This approach has the added benefit of being more\r
+reliable: any of the individual tagging operations might face a locked\r
+database, leading to partial results.\r
+\r
+This introduces a limitation to the number of messages that can be\r
+archived at the same time (through ARG_MAX limiting the command\r
+line). While at least on Linux this seems more like a theoretical\r
+limitation than a real one, it could be avoided by archiving at most a\r
+few hundred messages at a time.\r
+\r
+Based on code from Jani Nikula <jani@nikula.org>.\r
+---\r
+\r
+Batch all thread tagging rather than archive being a special case.\r
+\r
+ emacs/notmuch-show.el |   19 ++++++++++---------\r
+ 1 files changed, 10 insertions(+), 9 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 7469e2e..bbba482 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -1582,16 +1582,17 @@ argument, hide all of the messages."\r
+   (backward-button 1))\r
\r
+ (defun notmuch-show-tag-thread-internal (tag &optional remove)\r
+-  "Add tag to the current set of messages.\r
++  "Add TAG to the current set of messages.\r
\r
+-If the remove switch is given, tags will be removed instead of\r
+-added."\r
+-  (goto-char (point-min))\r
+-  (let ((tag-function (if remove\r
+-                        'notmuch-show-remove-tag\r
+-                      'notmuch-show-add-tag)))\r
+-    (loop do (funcall tag-function tag)\r
+-        until (not (notmuch-show-goto-message-next)))))\r
++If REMOVE is non-nil, TAG will be removed rather than added."\r
++  (save-excursion\r
++    (goto-char (point-min))\r
++    (let ((message-ids\r
++        (loop collect (notmuch-show-get-message-id)\r
++              until (not (notmuch-show-goto-message-next)))))\r
++      (if message-ids\r
++        (notmuch-tag (mapconcat #'identity message-ids " OR ")\r
++                     (concat (if remove "-" "+") tag))))))\r
\r
+ (defun notmuch-show-add-tag-thread (tag)\r
+   "Add tag to all messages in the current thread."\r
+-- \r
+1.7.8.3\r
+\r