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