[PATCH] emacs: call "notmuch tag" only once when archiving a thread
authorJani Nikula <jani@nikula.org>
Tue, 3 Jan 2012 18:29:06 +0000 (20:29 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:41:35 +0000 (09:41 -0800)
20/eb34cacf4d97101e5044800462a0ea732cb150 [new file with mode: 0644]

diff --git a/20/eb34cacf4d97101e5044800462a0ea732cb150 b/20/eb34cacf4d97101e5044800462a0ea732cb150
new file mode 100644 (file)
index 0000000..bc936c2
--- /dev/null
@@ -0,0 +1,116 @@
+Return-Path: <jani@nikula.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 D0E05431FD0\r
+       for <notmuch@notmuchmail.org>; Tue,  3 Jan 2012 10:29:12 -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 UBewZPwFdXlj for <notmuch@notmuchmail.org>;\r
+       Tue,  3 Jan 2012 10:29:12 -0800 (PST)\r
+Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com\r
+ [74.125.83.53])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ E8B57429E41   for <notmuch@notmuchmail.org>; Tue,  3 Jan 2012 10:29:11 -0800\r
+ (PST)\r
+Received: by eekd41 with SMTP id d41so19585040eek.26\r
+       for <notmuch@notmuchmail.org>; Tue, 03 Jan 2012 10:29:10 -0800 (PST)\r
+Received: by 10.14.126.80 with SMTP id a56mr22285191eei.121.1325615350459;\r
+       Tue, 03 Jan 2012 10:29:10 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
+       [80.220.92.23])\r
+       by mx.google.com with ESMTPS id b49sm177768025eec.9.2012.01.03.10.29.07\r
+       (version=SSLv3 cipher=OTHER); Tue, 03 Jan 2012 10:29:08 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] emacs: call "notmuch tag" only once when archiving a thread\r
+Date: Tue,  3 Jan 2012 20:29:06 +0200\r
+Message-Id: <1325615346-8302-1-git-send-email-jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.5.4\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: Tue, 03 Jan 2012 18:29:13 -0000\r
+\r
+Optimize thread archiving by combining all the -inbox tagging operations to\r
+a single "notmuch tag" call. Also skip redisplay of tag changes in current\r
+buffer, as it is immediately killed by the archiving functions.\r
+\r
+For threads in the order of tens or a hundred inbox tagged messages, this\r
+gives a noticeable speedup.\r
+\r
+On the downside, IIRC Xapian does not perform very well if the query (in\r
+this case a lot of message-ids OR'd together) is very big. It is unknown to\r
+me at which point this approach would become slower than the original one\r
+by one tagging approach, if ever.\r
+\r
+Also, this introduces a limitation to the number of messages that can be\r
+archived at the same time (through ARG_MAX limiting the command line). At\r
+least on Linux this seems more like a theoretical limitation than a real\r
+one.\r
+\r
+Signed-off-by: Jani Nikula <jani@nikula.org>\r
+\r
+---\r
+\r
+On my Linux machines, 'getconf ARG_MAX' gives 2097152, leading me to\r
+believe that notmuch-show would choke on the thread that would be limited\r
+by this anyway...\r
+---\r
+ emacs/notmuch-show.el |   23 ++++++++++++++++++++---\r
+ 1 files changed, 20 insertions(+), 3 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 5502efd..b9ea839 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -1414,11 +1414,28 @@ argument, hide all of the messages."\r
+   (interactive)\r
+   (backward-button 1))\r
\r
++(defun notmuch-show-thread-remove-tag (&rest toremove)\r
++  "Remove TOREMOVE tags from the current set of messages.\r
++\r
++Note: This function does not call `notmuch-show-set-tags' on the\r
++messages to redisplay the changed tags. This is meant to be\r
++called by `notmuch-show-archive-thread-internal' which kills the\r
++buffer afterwards."\r
++  (goto-char (point-min))\r
++  (let ((message-ids))\r
++    (loop do\r
++        (let* ((current-tags (notmuch-show-get-tags))\r
++               (new-tags (notmuch-show-del-tags-worker current-tags toremove)))\r
++          (unless (equal current-tags new-tags)\r
++            (add-to-list 'message-ids (notmuch-show-get-message-id))))\r
++        until (not (notmuch-show-goto-message-next)))\r
++    (when message-ids\r
++      (apply 'notmuch-tag (mapconcat 'identity message-ids " OR ")\r
++           (mapcar (lambda (s) (concat "-" s)) toremove)))))\r
++\r
+ (defun notmuch-show-archive-thread-internal (show-next)\r
+   ;; Remove the tag from the current set of messages.\r
+-  (goto-char (point-min))\r
+-  (loop do (notmuch-show-remove-tag "inbox")\r
+-      until (not (notmuch-show-goto-message-next)))\r
++  (notmuch-show-thread-remove-tag "inbox")\r
+   ;; Move to the next item in the search results, if any.\r
+   (let ((parent-buffer notmuch-show-parent-buffer))\r
+     (notmuch-kill-this-buffer)\r
+-- \r
+1.7.5.4\r
+\r