[PATCH] emacs: hello: use batch count
authorMark Walters <markwalters1009@gmail.com>
Tue, 15 Jan 2013 23:24:07 +0000 (23:24 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:53:07 +0000 (09:53 -0800)
48/822279a089ce5db2ecf4e2dbcaacf8114ab193 [new file with mode: 0644]

diff --git a/48/822279a089ce5db2ecf4e2dbcaacf8114ab193 b/48/822279a089ce5db2ecf4e2dbcaacf8114ab193
new file mode 100644 (file)
index 0000000..5fe4d9a
--- /dev/null
@@ -0,0 +1,148 @@
+Return-Path: <markwalters1009@gmail.com>\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 5C7B9431FBC\r
+       for <notmuch@notmuchmail.org>; Tue, 15 Jan 2013 15:24:12 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+       RCVD_IN_DNSWL_LOW=-0.7] 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 NM3jYqrmEPFH for <notmuch@notmuchmail.org>;\r
+       Tue, 15 Jan 2013 15:24:11 -0800 (PST)\r
+Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com\r
+       [209.85.212.178]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id B0E17431FAE\r
+       for <notmuch@notmuchmail.org>; Tue, 15 Jan 2013 15:24:11 -0800 (PST)\r
+Received: by mail-wi0-f178.google.com with SMTP id hn3so687148wib.11\r
+       for <notmuch@notmuchmail.org>; Tue, 15 Jan 2013 15:24:09 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to\r
+       :references; bh=2fS2ELl3uvqs/i0b+xLLBZAm4YQmyFSvmKAiY5TJZps=;\r
+       b=uGg64Y4hyl3XBmRlAhCfk7DmY2WWoiSU3evww04gAcUxQDXfptAFwzImFRNCAc5Tkb\r
+       igTjnD2LZDFlNhAL/zwatUftLAxHyR5ZO6HP7xDezlK+sb+tL5jUyNJyfevxCObuGZHN\r
+       JqiCAbo0/4aXJlE4mIJZoey99SQj5lbu/IvksE3wjqDCtlAaUFFCG6/ZrE2BCDsh+RwL\r
+       TipbgJOyMr58niR92yLrcTq6qhjqRBjzPFNjGI5u1IIFb8N9G7r8sYSb0cBOqu0pYsJx\r
+       cCQ8EnOsuq1hQCyGIM7SUZ0vagEPK4FAFnYMuIDq1wgXky+uP39ZyzuPnbIbEOgxaJNc\r
+       4E3g==\r
+X-Received: by 10.180.78.226 with SMTP id e2mr6459679wix.1.1358292249118;\r
+       Tue, 15 Jan 2013 15:24:09 -0800 (PST)\r
+Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
+       by mx.google.com with ESMTPS id t17sm6071706wiv.6.2013.01.15.15.24.07\r
+       (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+       Tue, 15 Jan 2013 15:24:08 -0800 (PST)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] emacs: hello: use batch count\r
+Date: Tue, 15 Jan 2013 23:24:07 +0000\r
+Message-Id: <1358292247-2059-1-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <cover.1358273133.git.jani@nikula.org>\r
+References: <cover.1358273133.git.jani@nikula.org>\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, 15 Jan 2013 23:24:12 -0000\r
+\r
+This modifies notmuch hello to use the new count --batch\r
+functionality. It should give exactly the same results as before but\r
+under many conditions it should be much faster. In particular it is\r
+much faster for remote use.\r
+\r
+The code is a little ugly as it has to do some working out of the\r
+query when asking the query and some when dealing with the result.\r
+However, the code path is exactly the same in both local and remote\r
+use.\r
+---\r
+\r
+It's a little ugly but seems to work and does give a useful speedup.\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+ emacs/notmuch-hello.el |   52 +++++++++++++++++++++++++++++------------------\r
+ 1 files changed, 32 insertions(+), 20 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
+index 6db62a0..2244892 100644\r
+--- a/emacs/notmuch-hello.el\r
++++ b/emacs/notmuch-hello.el\r
+@@ -381,26 +381,38 @@ The result is the list of elements of the form (NAME QUERY COUNT).\r
+ The values :show-empty-searches, :filter and :filter-count from\r
+ options will be handled as specified for\r
+ `notmuch-hello-insert-searches'."\r
+-  (notmuch-remove-if-not\r
+-   #'identity\r
+-   (mapcar\r
+-    (lambda (elem)\r
+-      (let* ((name (car elem))\r
+-           (query-and-count (if (consp (cdr elem))\r
+-                                ;; do we have a different query for the message count?\r
+-                                (cons (second elem) (third elem))\r
+-                              (cons (cdr elem) (cdr elem))))\r
+-           (message-count\r
+-            (string-to-number\r
+-             (notmuch-saved-search-count\r
+-              (notmuch-hello-filtered-query (cdr query-and-count)\r
+-                                            (or (plist-get options :filter-count)\r
+-                                               (plist-get options :filter)))))))\r
+-      (and (or (plist-get options :show-empty-searches) (> message-count 0))\r
+-           (list name (notmuch-hello-filtered-query\r
+-                       (car query-and-count) (plist-get options :filter))\r
+-                 message-count))))\r
+-    query-alist)))\r
++  (with-temp-buffer\r
++    (dolist (elem query-alist nil)\r
++      (let ((count-query (if (consp (cdr elem))\r
++                           ;; do we have a different query for the message count?\r
++                           (third elem)\r
++                         (cdr elem))))\r
++      (insert\r
++       (notmuch-hello-filtered-query count-query\r
++                                     (or (plist-get options :filter-count)\r
++                                         (plist-get options :filter)))\r
++       "\n")))\r
++\r
++    (call-process-region (point-min) (point-max) notmuch-command\r
++                       t t nil "count" "--batch")\r
++    (goto-char (point-min))\r
++\r
++    (notmuch-remove-if-not\r
++     #'identity\r
++     (mapcar\r
++      (lambda (elem)\r
++      (let ((name (car elem))\r
++            (search-query (if (consp (cdr elem))\r
++                               ;; do we have a different query for the message count?\r
++                               (second elem)\r
++                            (cdr elem)))\r
++            (message-count (prog1 (read (current-buffer))\r
++                              (forward-line 1))))\r
++        (and (or (plist-get options :show-empty-searches) (> message-count 0))\r
++             (list name (notmuch-hello-filtered-query\r
++                         search-query (plist-get options :filter))\r
++                   message-count))))\r
++      query-alist))))\r
\r
+ (defun notmuch-hello-insert-buttons (searches)\r
+   "Insert buttons for SEARCHES.\r
+-- \r
+1.7.9.1\r
+\r