From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 8F640431FAF for ; Wed, 8 Feb 2012 00:36:16 -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 E9qnuFwuzniN for ; Wed, 8 Feb 2012 00:36:16 -0800 (PST) Received: from mail-we0-f181.google.com (mail-we0-f181.google.com [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id CC641431FAE for ; Wed, 8 Feb 2012 00:36:15 -0800 (PST) Received: by werp13 with SMTP id p13so226628wer.26 for ; Wed, 08 Feb 2012 00:36:14 -0800 (PST) MIME-Version: 1.0 Received: by 10.180.85.105 with SMTP id g9mr24928515wiz.12.1328690174638; Wed, 08 Feb 2012 00:36:14 -0800 (PST) Received: from hotblack-desiato.hh.sledj.net (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25]) by mx.google.com with ESMTPS id y6sm25966710wix.10.2012.02.08.00.36.12 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 08 Feb 2012 00:36:13 -0800 (PST) Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000) id 9225EA168E; Wed, 8 Feb 2012 08:36:11 +0000 (GMT) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH v3] emacs: Call "notmuch tag" once when applying tag changes to a thread. Date: Wed, 8 Feb 2012 08:36:09 +0000 Message-Id: <1328690169-6991-1-git-send-email-dme@dme.org> X-Mailer: git-send-email 1.7.8.3 In-Reply-To: <1328632303-31877-1-git-send-email-jani@nikula.org> References: <1328632303-31877-1-git-send-email-jani@nikula.org> X-Gm-Message-State: ALoCoQnCh8lbUtOeBUbse3rVYDu+oSLvJj0aE8xRKOO12UAF+M1l7+W9WI7tk7gQLFJbLiM/TMRq 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: Wed, 08 Feb 2012 08:36:16 -0000 Optimize thread tagging by combining all the tagging operations to a single "notmuch tag" call. 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 approach has 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. Based on code from Jani Nikula . --- Batch all thread tagging rather than archive being a special case. emacs/notmuch-show.el | 19 ++++++++++--------- 1 files changed, 10 insertions(+), 9 deletions(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 7469e2e..bbba482 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -1582,16 +1582,17 @@ argument, hide all of the messages." (backward-button 1)) (defun notmuch-show-tag-thread-internal (tag &optional remove) - "Add tag to the current set of messages. + "Add TAG to the current set of messages. -If the remove switch is given, tags will be removed instead of -added." - (goto-char (point-min)) - (let ((tag-function (if remove - 'notmuch-show-remove-tag - 'notmuch-show-add-tag))) - (loop do (funcall tag-function tag) - until (not (notmuch-show-goto-message-next))))) +If REMOVE is non-nil, TAG will be removed rather than added." + (save-excursion + (goto-char (point-min)) + (let ((message-ids + (loop collect (notmuch-show-get-message-id) + until (not (notmuch-show-goto-message-next))))) + (if message-ids + (notmuch-tag (mapconcat #'identity message-ids " OR ") + (concat (if remove "-" "+") tag)))))) (defun notmuch-show-add-tag-thread (tag) "Add tag to all messages in the current thread." -- 1.7.8.3