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