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

diff --git a/1d/4664864d537f7f8d55fca4980489cd3e73f0a0 b/1d/4664864d537f7f8d55fca4980489cd3e73f0a0
new file mode 100644 (file)
index 0000000..ae43167
--- /dev/null
@@ -0,0 +1,116 @@
+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 20375431FAF\r
+       for <notmuch@notmuchmail.org>; Wed,  8 Feb 2012 08:43:23 -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 cMW6S8zsDrmC for <notmuch@notmuchmail.org>;\r
+       Wed,  8 Feb 2012 08:43:22 -0800 (PST)\r
+Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com\r
+       [209.85.212.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 62AA3431FAE\r
+       for <notmuch@notmuchmail.org>; Wed,  8 Feb 2012 08:43:22 -0800 (PST)\r
+Received: by wibhi8 with SMTP id hi8so581880wib.26\r
+       for <notmuch@notmuchmail.org>; Wed, 08 Feb 2012 08:43:19 -0800 (PST)\r
+Received: by 10.180.108.232 with SMTP id hn8mr41994257wib.16.1328719399738;\r
+       Wed, 08 Feb 2012 08:43:19 -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 dr5sm4624285wib.0.2012.02.08.08.43.17\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Wed, 08 Feb 2012 08:43:18 -0800 (PST)\r
+Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
+       id 4CC9FA065C; Wed,  8 Feb 2012 16:43:16 +0000 (GMT)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v4] emacs: Call "notmuch tag" once when applying tag changes\r
+       to a thread.\r
+Date: Wed,  8 Feb 2012 16:43:15 +0000\r
+Message-Id: <1328719395-6333-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-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 16:43:23 -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
+v4:\r
+- Rebased after Dmitry's tagging changes (yay!).\r
+\r
+ emacs/notmuch-show.el |   18 +++++++++++-------\r
+ 1 files changed, 11 insertions(+), 7 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index faa9f9b..9294bc8 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -1599,14 +1599,18 @@ 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 ((op (if remove "-" "+")))\r
+-    (loop do (notmuch-show-tag-message (concat op 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 ((tag-op (concat (if remove "-" "+") tag))\r
++        (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
++                     tag-op)))))\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