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 45279431FC3 for ; Sun, 31 Mar 2013 02:46:30 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" 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 2H8MENHFpXB5 for ; Sun, 31 Mar 2013 02:46:29 -0700 (PDT) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com [209.85.215.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id A3F94429E35 for ; Sun, 31 Mar 2013 02:46:24 -0700 (PDT) Received: by mail-la0-f45.google.com with SMTP id er20so1462708lab.32 for ; Sun, 31 Mar 2013 02:46:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:in-reply-to:references:x-gm-message-state; bh=2xAOn7Li7EL6Z30EI/5y7AAh4fM0Ecb7KaJmOTAgp20=; b=W5CWbcXahFMus7Gq5a9fyEYVENtdAnwcyZ9vxCb0dku/bZqmCDqOzd/X7eccjLqVPm OEuOUHac2J/JBmRjaPocJ7O8Hlg0fgez5J6DGmeXCtkYkR/DqDQted+78NAXkjUKNCyk MelQwjLaISrTIw2RRpvkwvC5yOn7JF8CENP+ag18TK1glG6ChGftfeB3sAHSfnHnQ/Fl FC8eKF/ubdvsMe6qc4zunbjcIiohTyUBzeqNAgb7Zc+FHTlXYEr7QvFvNTLBczHok/so j58rW/dy9JR6GjLu+GyY/53tWzkpGuIuRkcpPgGxDJvgjIwbEE22UXKRCsuG6QzdemCK Opwg== X-Received: by 10.112.99.5 with SMTP id em5mr4078672lbb.1.1364723183195; Sun, 31 Mar 2013 02:46:23 -0700 (PDT) Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi. [80.223.81.27]) by mx.google.com with ESMTPS id q9sm3742335lbz.3.2013.03.31.02.46.21 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 31 Mar 2013 02:46:22 -0700 (PDT) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH v3 6/6] emacs: hello: use batch count Date: Sun, 31 Mar 2013 12:46:03 +0300 Message-Id: X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: In-Reply-To: References: X-Gm-Message-State: ALoCoQky46uejxIIOpQHNk9P4qWHh79OIsgh42X1tMLdrRgNC/yrLZw53iTmDcIACCmZfG7CTf7D Cc: Tomi Ollila 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: Sun, 31 Mar 2013 09:46:30 -0000 From: Mark Walters 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. --- emacs/notmuch-hello.el | 52 +++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index 00b78e1..cda79f1 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.10.4