unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH v2] emacs: call "notmuch tag" only once when archiving a thread
@ 2012-02-07 16:31 Jani Nikula
  2012-02-08  8:36 ` [PATCH v3] emacs: Call "notmuch tag" once when applying tag changes to " David Edmondson
  2012-02-08 16:43 ` [PATCH v4] " David Edmondson
  0 siblings, 2 replies; 5+ messages in thread
From: Jani Nikula @ 2012-02-07 16:31 UTC (permalink / raw)
  To: notmuch

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 <jani@nikula.org>

---

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-02-08 16:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-07 16:31 [PATCH v2] emacs: call "notmuch tag" only once when archiving a thread Jani Nikula
2012-02-08  8:36 ` [PATCH v3] emacs: Call "notmuch tag" once when applying tag changes to " David Edmondson
2012-02-08  9:59   ` Tomi Ollila
2012-02-08 16:43 ` [PATCH v4] " David Edmondson
2012-02-08 16:56   ` Dmitry Kurochkin

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).