From: Jani Nikula Date: Tue, 7 Feb 2012 16:31:43 +0000 (+0200) Subject: [PATCH v2] emacs: call "notmuch tag" only once when archiving a thread X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=679da9b8fc589b0802b1752623089158e820cd95;p=notmuch-archives.git [PATCH v2] emacs: call "notmuch tag" only once when archiving a thread --- diff --git a/73/38087be745de6c26307133b011a8c1fbbd8a18 b/73/38087be745de6c26307133b011a8c1fbbd8a18 new file mode 100644 index 000000000..96a135917 --- /dev/null +++ b/73/38087be745de6c26307133b011a8c1fbbd8a18 @@ -0,0 +1,130 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id BCD6C431FB6 + for ; Tue, 7 Feb 2012 08:31:51 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 1njgVp-3lmCP for ; + Tue, 7 Feb 2012 08:31:51 -0800 (PST) +Received: from mail-lpp01m020-f181.google.com (mail-lpp01m020-f181.google.com + [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id C0EB3431FAE + for ; Tue, 7 Feb 2012 08:31:50 -0800 (PST) +Received: by lbbgn5 with SMTP id gn5so2262169lbb.26 + for ; Tue, 07 Feb 2012 08:31:49 -0800 (PST) +Received: by 10.152.148.9 with SMTP id to9mr5720507lab.1.1328632308988; + Tue, 07 Feb 2012 08:31:48 -0800 (PST) +Received: from localhost (dsl-hkibrasgw4-fe50f800-253.dhcp.inet.fi. + [84.248.80.253]) + by mx.google.com with ESMTPS id m3sm16124590lbm.17.2012.02.07.08.31.44 + (version=SSLv3 cipher=OTHER); Tue, 07 Feb 2012 08:31:46 -0800 (PST) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH v2] emacs: call "notmuch tag" only once when archiving a + thread +Date: Tue, 7 Feb 2012 18:31:43 +0200 +Message-Id: <1328632303-31877-1-git-send-email-jani@nikula.org> +X-Mailer: git-send-email 1.7.5.4 +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Tue, 07 Feb 2012 16:31:51 -0000 + +Optimize thread archiving by combining all the -inbox tagging +operations to a single "notmuch tag" call. Also skip redisplay of tag +changes in current buffer, as it is immediately killed by the +archiving functions. + +For threads in the order of tens or a hundred inbox tagged messages, +this gives a noticeable speedup. On two different machines, archiving +a thread of about 50 inbox tagged messages goes down from 10+ seconds +to about 0.5 seconds. + +The bottleneck is not within emacs; the same behaviour can be observed +in the cli. This patch is a quick fix to thread archiving, but it +seems clear that generally the thread tagging functions should be +refactored to do tagging in one go. This approach would have the added +benefit of being more reliable: any of the individual tagging +operations might face a locked database, leading to partial results. + +This introduces a limitation to the number of messages that can be +archived at the same time (through ARG_MAX limiting the command +line). While at least on Linux this seems more like a theoretical +limitation than a real one, it could be avoided by archiving at most a +few hundred messages at a time. + +Signed-off-by: Jani Nikula + +--- + +v1 is at id:"1325615346-8302-1-git-send-email-jani@nikula.org". + +Although this saves me several minutes a day, I don't have the time +for further improvements. I'm just too slow writing elisp... +--- + emacs/notmuch-show.el | 19 +++++++++++++++++-- + 1 files changed, 17 insertions(+), 2 deletions(-) + +diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el +index 7469e2e..a0b8eb3 100644 +--- a/emacs/notmuch-show.el ++++ b/emacs/notmuch-show.el +@@ -1614,6 +1614,21 @@ added." + (if show-next + (notmuch-search-show-thread))))) + ++(defun notmuch-show-archive-thread-quick () ++ "Remove \"inbox\" tag from the current set of messages. ++ ++Note: This function does not call `notmuch-show-set-tags' on the ++messages to redisplay the changed tags. This is meant to be ++called by functions that archive the messages and kill the buffer ++afterwards." ++ (goto-char (point-min)) ++ (let (message-ids) ++ (loop do ++ (add-to-list 'message-ids (notmuch-show-get-message-id)) ++ until (not (notmuch-show-goto-message-next))) ++ (when message-ids ++ (notmuch-tag (mapconcat 'identity message-ids " OR ") "-inbox")))) ++ + (defun notmuch-show-archive-thread (&optional unarchive) + "Archive each message in thread. + +@@ -1637,13 +1652,13 @@ buffer." + (defun notmuch-show-archive-thread-then-next () + "Archive each message in thread, then show next thread from search." + (interactive) +- (notmuch-show-archive-thread) ++ (notmuch-show-archive-thread-quick) + (notmuch-show-next-thread t)) + + (defun notmuch-show-archive-thread-then-exit () + "Archive each message in thread, then exit back to search results." + (interactive) +- (notmuch-show-archive-thread) ++ (notmuch-show-archive-thread-quick) + (notmuch-show-next-thread)) + + (defun notmuch-show-archive-message (&optional unarchive) +-- +1.7.5.4 +