1 Return-Path: <jani@nikula.org>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id F2B20429E36
\r
6 for <notmuch@notmuchmail.org>; Sun, 13 Nov 2011 11:48:54 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"
\r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
13 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id nYKGpEgQyIfy for <notmuch@notmuchmail.org>;
\r
17 Sun, 13 Nov 2011 11:48:53 -0800 (PST)
\r
18 Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com
\r
19 [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 72347429E31
\r
22 for <notmuch@notmuchmail.org>; Sun, 13 Nov 2011 11:48:50 -0800 (PST)
\r
23 Received: by mail-bw0-f53.google.com with SMTP id q10so6225076bka.26
\r
24 for <notmuch@notmuchmail.org>; Sun, 13 Nov 2011 11:48:50 -0800 (PST)
\r
25 Received: by 10.204.10.81 with SMTP id o17mr16483654bko.65.1321213729960;
\r
26 Sun, 13 Nov 2011 11:48:49 -0800 (PST)
\r
27 Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.
\r
29 by mx.google.com with ESMTPS id e18sm6369993bkr.15.2011.11.13.11.48.46
\r
30 (version=SSLv3 cipher=OTHER); Sun, 13 Nov 2011 11:48:48 -0800 (PST)
\r
31 From: Jani Nikula <jani@nikula.org>
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [PATCH v5 1/6] lib: add function to get the number of threads
\r
35 Date: Sun, 13 Nov 2011 21:48:35 +0200
\r
37 <a6b88f21c57d64605f25235a3a82264fc837d252.1321212673.git.jani@nikula.org>
\r
38 X-Mailer: git-send-email 1.7.5.4
\r
39 In-Reply-To: <cover.1321212673.git.jani@nikula.org>
\r
40 References: <cover.1321212673.git.jani@nikula.org>
\r
41 In-Reply-To: <cover.1321212673.git.jani@nikula.org>
\r
42 References: <cover.1321212673.git.jani@nikula.org>
\r
43 X-BeenThere: notmuch@notmuchmail.org
\r
44 X-Mailman-Version: 2.1.13
\r
46 List-Id: "Use and development of the notmuch mail system."
\r
47 <notmuch.notmuchmail.org>
\r
48 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
49 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
50 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
51 List-Post: <mailto:notmuch@notmuchmail.org>
\r
52 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
53 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
54 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
55 X-List-Received-Date: Sun, 13 Nov 2011 19:48:55 -0000
\r
57 Add function notmuch_query_count_threads() to get the number of threads
\r
58 matching a search. This is done by performing a search and figuring out the
\r
59 number of unique thread IDs in the matching messages, a significantly
\r
60 heavier operation than notmuch_query_count_messages().
\r
62 Signed-off-by: Jani Nikula <jani@nikula.org>
\r
64 lib/notmuch.h | 14 ++++++++++++++
\r
65 lib/query.cc | 44 ++++++++++++++++++++++++++++++++++++++++++++
\r
66 2 files changed, 58 insertions(+), 0 deletions(-)
\r
68 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
69 index c4330e4..9f23a10 100644
\r
72 @@ -609,6 +609,20 @@ notmuch_threads_destroy (notmuch_threads_t *threads);
\r
74 notmuch_query_count_messages (notmuch_query_t *query);
\r
76 +/* Return the number of threads matching a search.
\r
78 + * This function performs a search and returns the number of unique thread IDs
\r
79 + * in the matching messages. This is the same as number of threads matching a
\r
82 + * Note that this is a significantly heavier operation than
\r
83 + * notmuch_query_count_messages().
\r
85 + * If an error occurs, this function may return 0.
\r
88 +notmuch_query_count_threads (notmuch_query_t *query);
\r
90 /* Get the thread ID of 'thread'.
\r
92 * The returned string belongs to 'thread' and as such, should not be
\r
93 diff --git a/lib/query.cc b/lib/query.cc
\r
94 index 6f02b04..b6c0f12 100644
\r
97 @@ -457,3 +457,47 @@ notmuch_query_count_messages (notmuch_query_t *query)
\r
103 +notmuch_query_count_threads (notmuch_query_t *query)
\r
105 + notmuch_messages_t *messages;
\r
106 + GHashTable *hash;
\r
107 + unsigned int count;
\r
108 + notmuch_sort_t sort;
\r
110 + sort = query->sort;
\r
111 + query->sort = NOTMUCH_SORT_UNSORTED;
\r
112 + messages = notmuch_query_search_messages (query);
\r
113 + query->sort = sort;
\r
114 + if (messages == NULL)
\r
117 + hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
\r
118 + if (hash == NULL) {
\r
119 + talloc_free (messages);
\r
123 + while (notmuch_messages_valid (messages)) {
\r
124 + notmuch_message_t *message = notmuch_messages_get (messages);
\r
125 + const char *thread_id = notmuch_message_get_thread_id (message);
\r
126 + char *thread_id_copy = talloc_strdup (messages, thread_id);
\r
127 + if (unlikely (thread_id_copy == NULL)) {
\r
128 + notmuch_message_destroy (message);
\r
132 + g_hash_table_insert (hash, thread_id_copy, NULL);
\r
133 + notmuch_message_destroy (message);
\r
134 + notmuch_messages_move_to_next (messages);
\r
137 + count = g_hash_table_size (hash);
\r
140 + g_hash_table_unref (hash);
\r
141 + talloc_free (messages);
\r