[WIP 1/2] lib: multithread
authorMark Walters <markwalters1009@gmail.com>
Tue, 20 Mar 2012 20:11:59 +0000 (20:11 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:45:38 +0000 (09:45 -0800)
f9/f199a47f38b3847ea7e1775d616e35ac17e73c [new file with mode: 0644]

diff --git a/f9/f199a47f38b3847ea7e1775d616e35ac17e73c b/f9/f199a47f38b3847ea7e1775d616e35ac17e73c
new file mode 100644 (file)
index 0000000..717f5a1
--- /dev/null
@@ -0,0 +1,178 @@
+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 215A9431FC3\r
+       for <notmuch@notmuchmail.org>; Tue, 20 Mar 2012 13:12:16 -0700 (PDT)\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 bG0v1JxlnyuF for <notmuch@notmuchmail.org>;\r
+       Tue, 20 Mar 2012 13:12:14 -0700 (PDT)\r
+Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com\r
+       [209.85.212.179]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 251F0431FAF\r
+       for <notmuch@notmuchmail.org>; Tue, 20 Mar 2012 13:12:09 -0700 (PDT)\r
+Received: by wibhn6 with SMTP id hn6so483852wib.2\r
+       for <notmuch@notmuchmail.org>; Tue, 20 Mar 2012 13:12:06 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+       bh=rR1OelO4n28O8ZniT3jdS1YEJTRztUVQm3KpcBm2Tok=;\r
+       b=x00ylADwCdt+1fDbqVvXl6HgkAoivqAzol/zIkH/8/UkU/BEMG2CBfvn8xvcsERIHN\r
+       m2G6cg4KCuRFBF2u14B5rwaqLUN0UDsVPanJvv0Iacdl6D+j+zOCkN4S2QbvozM9mAkb\r
+       95BoN1NlN+jj2BXP72e7PYUGcji+bFai/x54uZG+azk9PS2cwNDZJKRw/SrXHYuI2zw3\r
+       QV/nvukBjdQsFcEjIucdFZON30S7HkLE5ydQQZuHcbeKOIq6NEcCpbTd7A3CmQIznklK\r
+       9Mcci65Oyuaq294Ku5HRqwoUGobNU+Y88gN4d24wWSJt1jNYluQv2Cq/CIPvjIzOIToz\r
+       Juxw==\r
+Received: by 10.180.19.196 with SMTP id h4mr2769699wie.12.1332274326437;\r
+       Tue, 20 Mar 2012 13:12:06 -0700 (PDT)\r
+Received: from localhost (94-192-233-223.zone6.bethere.co.uk.\r
+ [94.192.233.223])     by mx.google.com with ESMTPS id\r
+ ff9sm36556794wib.2.2012.03.20.13.12.04        (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Tue, 20 Mar 2012 13:12:05 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [WIP 1/2] lib: multithread\r
+Date: Tue, 20 Mar 2012 20:11:59 +0000\r
+Message-Id: <1332274320-17487-2-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1332274320-17487-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1332274320-17487-1-git-send-email-markwalters1009@gmail.com>\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, 20 Mar 2012 20:12:16 -0000\r
+\r
+---\r
+ lib/notmuch.h |   12 ++++++++++++\r
+ lib/query.cc  |   46 +++++++++++++++++++++++++++++++++++++++++++++-\r
+ 2 files changed, 57 insertions(+), 1 deletions(-)\r
+\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index babd208..22dd69e 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -445,6 +445,18 @@ typedef enum {\r
+     NOTMUCH_SORT_UNSORTED\r
+ } notmuch_sort_t;\r
+ \r
++/* Values for notmuch_query_secondary_search_conjunction */\r
++typedef enum {\r
++    NOTMUCH_SECONDARY_SEARCH_NONE,\r
++    NOTMUCH_SECONDARY_SEARCH_AND,\r
++    NOTMUCH_SECONDARY_SEARCH_AND_NOT\r
++} notmuch_ss_conjunction_t;\r
++\r
++void\r
++notmuch_query_set_secondary_search (notmuch_query_t *query,\r
++                                  const char *secondary_search_terms,\r
++                                  notmuch_ss_conjunction_t conjunction);\r
++\r
+ /* Return the query_string of this query. See notmuch_query_create. */\r
+ const char *\r
+ notmuch_query_get_query_string (notmuch_query_t *query);\r
+diff --git a/lib/query.cc b/lib/query.cc\r
+index 68ac1e4..0faef51 100644\r
+--- a/lib/query.cc\r
++++ b/lib/query.cc\r
+@@ -26,6 +26,8 @@\r
+ struct _notmuch_query {\r
+     notmuch_database_t *notmuch;\r
+     const char *query_string;\r
++    const char *secondary_search_terms;\r
++    notmuch_ss_conjunction_t ss_conjunction;\r
+     notmuch_sort_t sort;\r
+     notmuch_string_list_t *exclude_terms;\r
+     notmuch_bool_t omit_excluded_messages;\r
+@@ -92,6 +94,8 @@ notmuch_query_create (notmuch_database_t *notmuch,\r
+ \r
+     query->exclude_terms = _notmuch_string_list_create (query);\r
+ \r
++    query->secondary_search_terms = NULL;\r
++\r
+     query->omit_excluded_messages = FALSE;\r
+ \r
+     return query;\r
+@@ -122,6 +126,15 @@ notmuch_query_get_sort (notmuch_query_t *query)\r
+ }\r
+ \r
+ void\r
++notmuch_query_set_secondary_search (notmuch_query_t *query,\r
++                                  const char *secondary_search_terms,\r
++                                  notmuch_ss_conjunction_t conjunction)\r
++{\r
++    query->secondary_search_terms = talloc_strdup (query, secondary_search_terms);\r
++    query->ss_conjunction = conjunction;\r
++}\r
++\r
++void\r
+ notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag)\r
+ {\r
+     char *term = talloc_asprintf (query, "%s%s", _find_prefix ("tag"), tag);\r
+@@ -454,6 +467,36 @@ notmuch_query_destroy (notmuch_query_t *query)\r
+     talloc_free (query);\r
+ }\r
+ \r
++/* This function tests whether the thread containing document with id\r
++ * seed_doc_id satisfies the secondary search terms of query.*/\r
++notmuch_bool_t\r
++notmuch_thread_test_secondary_search (notmuch_query_t *query, unsigned int seed_doc_id)\r
++{\r
++    int count;\r
++    notmuch_message_t *seed_message;\r
++    const char *thread_id;\r
++    char *thread_id_query_string;\r
++    notmuch_query_t *thread_id_query;\r
++\r
++    if (!query->secondary_search_terms) return TRUE;\r
++    seed_message = _notmuch_message_create (query, query->notmuch, seed_doc_id, NULL);\r
++\r
++    thread_id = notmuch_message_get_thread_id (seed_message);\r
++    thread_id_query_string = talloc_asprintf (query, "thread:%s and %s",\r
++                                            thread_id,\r
++                                            query->secondary_search_terms);\r
++    thread_id_query = notmuch_query_create (query->notmuch, thread_id_query_string);\r
++    count = notmuch_query_count_messages (thread_id_query);\r
++    switch (query->ss_conjunction) {\r
++    case NOTMUCH_SECONDARY_SEARCH_AND:\r
++      return (count > 0);\r
++    case NOTMUCH_SECONDARY_SEARCH_AND_NOT:\r
++      return (count == 0);\r
++    default:\r
++      return TRUE;\r
++    }\r
++}\r
++\r
+ notmuch_bool_t\r
+ notmuch_threads_valid (notmuch_threads_t *threads)\r
+ {\r
+@@ -462,7 +505,8 @@ notmuch_threads_valid (notmuch_threads_t *threads)\r
+     while (threads->doc_id_pos < threads->doc_ids->len) {\r
+       doc_id = g_array_index (threads->doc_ids, unsigned int,\r
+                               threads->doc_id_pos);\r
+-      if (_notmuch_doc_id_set_contains (&threads->match_set, doc_id))\r
++      if (_notmuch_doc_id_set_contains (&threads->match_set, doc_id) &&\r
++          notmuch_thread_test_secondary_search (threads->query, doc_id))\r
+           break;\r
+ \r
+       threads->doc_id_pos++;\r
+-- \r
+1.7.9.1\r
+\r