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 409BC431FC2 for ; Sat, 9 Mar 2013 07:13:07 -0800 (PST) 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 DdHd3rKlyCar for ; Sat, 9 Mar 2013 07:13:05 -0800 (PST) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com [209.85.217.178]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 2AB41431FAE for ; Sat, 9 Mar 2013 07:12:57 -0800 (PST) Received: by mail-lb0-f178.google.com with SMTP id n1so2077124lba.37 for ; Sat, 09 Mar 2013 07:12:55 -0800 (PST) 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=KeflAwsyi9rnx+H7LGa5pHKeBbdsL8obcaDmq1zs8PmPNQUWC0OZ9+QapIy/z3WF0d UBBLrVEQbSP7wOTK90TykqV91zzpvbg9eWtVO1+p3odfTh1z9b8Lr3MHesGwHfhcxQqF V9xeW1VDAZ/8XDtTkrIdDiasTRJ/uYJhE72NAYWhBmnlEF3oh04wXJ+0vN5D1vuLZE1B PAV5oJC5Mn5PDCET5MBpwZEPw9tao4n7PIE2GFQb7Tcnavfda3gxCYFfoma1j5sjmMQn BifZn08AGtLDRI9kEHcRL0RbNo78Dg7baybD2+OCbOYBJWYYTFq3hf+zoSjwRSIuDWuY Uc1A== X-Received: by 10.152.110.6 with SMTP id hw6mr5221950lab.43.1362841975719; Sat, 09 Mar 2013 07:12:55 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi. [80.223.81.27]) by mx.google.com with ESMTPS id xw14sm4276065lab.6.2013.03.09.07.12.53 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 09 Mar 2013 07:12:55 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH v2 6/6] emacs: hello: use batch count Date: Sat, 9 Mar 2013 17:12:26 +0200 Message-Id: <09827d9c7e237b45955bb1c96d802ebd7887f868.1362841844.git.jani@nikula.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: In-Reply-To: References: X-Gm-Message-State: ALoCoQlemJFMDyEwRJvGeh3fu3ItA3fve8PRLOZyZrEk1vh532zytIdKBsrx/g6P/IZxjlUeO3MH 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: Sat, 09 Mar 2013 15:13:07 -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