[PATCH v2] emacs: call "notmuch tag" only once when archiving a thread
authorJani Nikula <jani@nikula.org>
Tue, 7 Feb 2012 16:31:43 +0000 (18:31 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:44:15 +0000 (09:44 -0800)
73/38087be745de6c26307133b011a8c1fbbd8a18 [new file with mode: 0644]

diff --git a/73/38087be745de6c26307133b011a8c1fbbd8a18 b/73/38087be745de6c26307133b011a8c1fbbd8a18
new file mode 100644 (file)
index 0000000..96a1359
--- /dev/null
@@ -0,0 +1,130 @@
+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 BCD6C431FB6\r
+       for <notmuch@notmuchmail.org>; Tue,  7 Feb 2012 08:31:51 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       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 1njgVp-3lmCP for <notmuch@notmuchmail.org>;\r
+       Tue,  7 Feb 2012 08:31:51 -0800 (PST)\r
+Received: from mail-lpp01m020-f181.google.com (mail-lpp01m020-f181.google.com\r
+       [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id C0EB3431FAE\r
+       for <notmuch@notmuchmail.org>; Tue,  7 Feb 2012 08:31:50 -0800 (PST)\r
+Received: by lbbgn5 with SMTP id gn5so2262169lbb.26\r
+       for <notmuch@notmuchmail.org>; Tue, 07 Feb 2012 08:31:49 -0800 (PST)\r
+Received: by 10.152.148.9 with SMTP id to9mr5720507lab.1.1328632308988;\r
+       Tue, 07 Feb 2012 08:31:48 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-fe50f800-253.dhcp.inet.fi.\r
+       [84.248.80.253])\r
+       by mx.google.com with ESMTPS id m3sm16124590lbm.17.2012.02.07.08.31.44\r
+       (version=SSLv3 cipher=OTHER); Tue, 07 Feb 2012 08:31:46 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2] emacs: call "notmuch tag" only once when archiving a\r
+ thread\r
+Date: Tue,  7 Feb 2012 18:31:43 +0200\r
+Message-Id: <1328632303-31877-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, 07 Feb 2012 16:31:51 -0000\r
+\r
+Optimize thread archiving by combining all the -inbox tagging\r
+operations to a single "notmuch tag" call. Also skip redisplay of tag\r
+changes in current buffer, as it is immediately killed by the\r
+archiving functions.\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 patch is a quick fix to thread archiving, but it\r
+seems clear that generally the thread tagging functions should be\r
+refactored to do tagging in one go. This approach would have the added\r
+benefit of being more reliable: any of the individual tagging\r
+operations might face a locked 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
+Signed-off-by: Jani Nikula <jani@nikula.org>\r
+\r
+---\r
+\r
+v1 is at id:"1325615346-8302-1-git-send-email-jani@nikula.org".\r
+\r
+Although this saves me several minutes a day, I don't have the time\r
+for further improvements. I'm just too slow writing elisp...\r
+---\r
+ emacs/notmuch-show.el |   19 +++++++++++++++++--\r
+ 1 files changed, 17 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 7469e2e..a0b8eb3 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -1614,6 +1614,21 @@ added."\r
+       (if show-next\r
+         (notmuch-search-show-thread)))))\r
+ \r
++(defun notmuch-show-archive-thread-quick ()\r
++  "Remove \"inbox\" tag 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 functions that archive the messages and kill the buffer\r
++afterwards."\r
++  (goto-char (point-min))\r
++  (let (message-ids)\r
++    (loop do\r
++        (add-to-list 'message-ids (notmuch-show-get-message-id))\r
++        until (not (notmuch-show-goto-message-next)))\r
++    (when message-ids\r
++      (notmuch-tag (mapconcat 'identity message-ids " OR ") "-inbox"))))\r
++\r
+ (defun notmuch-show-archive-thread (&optional unarchive)\r
+   "Archive each message in thread.\r
+ \r
+@@ -1637,13 +1652,13 @@ buffer."\r
+ (defun notmuch-show-archive-thread-then-next ()\r
+   "Archive each message in thread, then show next thread from search."\r
+   (interactive)\r
+-  (notmuch-show-archive-thread)\r
++  (notmuch-show-archive-thread-quick)\r
+   (notmuch-show-next-thread t))\r
+ \r
+ (defun notmuch-show-archive-thread-then-exit ()\r
+   "Archive each message in thread, then exit back to search results."\r
+   (interactive)\r
+-  (notmuch-show-archive-thread)\r
++  (notmuch-show-archive-thread-quick)\r
+   (notmuch-show-next-thread))\r
+ \r
+ (defun notmuch-show-archive-message (&optional unarchive)\r
+-- \r
+1.7.5.4\r
+\r