--- /dev/null
+Return-Path: <m.walters@qmul.ac.uk>\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 E4F21429E34\r
+ for <notmuch@notmuchmail.org>; Tue, 31 Jan 2012 03:44:38 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.098\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
+ tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+ NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 g7IAq5B7TMLf for <notmuch@notmuchmail.org>;\r
+ Tue, 31 Jan 2012 03:44:38 -0800 (PST)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id B7ED6431E64\r
+ for <notmuch@notmuchmail.org>; Tue, 31 Jan 2012 03:44:37 -0800 (PST)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+ by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1RsC8Z-0003xS-Nt; Tue, 31 Jan 2012 11:44:36 +0000\r
+Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223]\r
+ helo=localhost)\r
+ by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1RsC8Z-0006ft-6z; Tue, 31 Jan 2012 11:44:35 +0000\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Austin Clements <amdragon@MIT.EDU>\r
+Subject: Re: [PATCH 3/7] lib: Make notmuch_query_search_messages set the\r
+ exclude flag\r
+In-Reply-To: <20120131044352.GZ17991@mit.edu>\r
+References: <8762fu4aqt.fsf@qmul.ac.uk>\r
+ <1327862394-14334-3-git-send-email-markwalters1009@gmail.com>\r
+ <20120131044352.GZ17991@mit.edu>\r
+User-Agent: Notmuch/0.11+137~g98adc3d (http://notmuchmail.org) Emacs/23.2.1\r
+ (i486-pc-linux-gnu)\r
+Date: Tue, 31 Jan 2012 11:45:41 +0000\r
+Message-ID: <87y5soccyi.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 94.192.233.223\r
+X-QM-SPAM-Info: Sender has good ham record. :)\r
+X-QM-Body-MD5: a1fd102ac7732633f006b6340c8647ed (of first 20000 bytes)\r
+X-SpamAssassin-Score: -1.8\r
+X-SpamAssassin-SpamBar: -\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+ determine if it is\r
+ spam. We require at least 5.0 points to mark a message as spam.\r
+ This message scored -1.8 points.\r
+ Summary of the scoring: \r
+ * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
+ * medium trust\r
+ * [138.37.6.40 listed in list.dnswl.org]\r
+ * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+ provider * (markwalters1009[at]gmail.com)\r
+ * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
+ * domain\r
+ * 0.5 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\r
+Cc: notmuch@notmuchmail.org\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, 31 Jan 2012 11:44:39 -0000\r
+\r
+On Mon, 30 Jan 2012 23:43:52 -0500, Austin Clements <amdragon@MIT.EDU> wrote:\r
+> Quoth Mark Walters on Jan 29 at 6:39 pm:\r
+> > Add a flag NOTMUCH_MESSAGE_FLAG_EXCLUDED which is set by\r
+> > notmuch_query_search_messages for excluded messages. Also add an\r
+> > option omit_excluded_messages to the search that we do not want the\r
+> > excludes at all.\r
+> > \r
+> > This exclude flag will be added to notmuch_query_search threads in the\r
+> > next patch.\r
+> > ---\r
+> > lib/notmuch-private.h | 1 +\r
+> > lib/notmuch.h | 8 ++++++-\r
+> > lib/query.cc | 52 +++++++++++++++++++++++++++++++++++++++++++++---\r
+> > 3 files changed, 56 insertions(+), 5 deletions(-)\r
+> > \r
+> > diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+> > index 7bf153e..e791bb0 100644\r
+> > --- a/lib/notmuch-private.h\r
+> > +++ b/lib/notmuch-private.h\r
+> > @@ -401,6 +401,7 @@ typedef struct _notmuch_message_list {\r
+> > */\r
+> > struct visible _notmuch_messages {\r
+> > notmuch_bool_t is_of_list_type;\r
+> > + notmuch_doc_id_set_t *excluded_doc_ids;\r
+> \r
+> I might be following the diff wrong, but shouldn't this be a field of\r
+> notmuch_mset_messages_t? (Then it also doesn't have to be a pointer,\r
+> which is really how notmuch_doc_id_set_t was designed to be used.)\r
+\r
+I will need to think about that.\r
+\r
+> > notmuch_message_node_t *iterator;\r
+> > };\r
+> > \r
+> > diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+> > index 7929fe7..740d005 100644\r
+> > --- a/lib/notmuch.h\r
+> > +++ b/lib/notmuch.h\r
+> > @@ -449,6 +449,11 @@ typedef enum {\r
+> > const char *\r
+> > notmuch_query_get_query_string (notmuch_query_t *query);\r
+> > \r
+> > +/* specify whether to results should omit the excluded results rather\r
+> > + * than just marking them excluded */\r
+> > +void\r
+> > +notmuch_query_set_omit_excluded_messages (notmuch_query_t *query, notmuch_bool_t omit);\r
+> > +\r
+> \r
+> I don't think we should add this API. The library behavior will not\r
+> change for library users that don't use excludes and library users\r
+> that do use excludes should by aware of the excluded flag and do the\r
+> appropriate thing.\r
+> \r
+> I can see why this is handy in some cases, but I don't think it\r
+> provides enough utility to warrant becoming part of the permanent and\r
+> minimal library interface.\r
+\r
+This is really a performance improvement: suppose that there are lots of\r
+threads that only match in excluded messages. Then without this flag we\r
+will spend lots of time constructing the thread only for it to be\r
+ignored. (In contrived situations this could be arbitrarily slower.)\r
+\r
+Note the benchmarks were against master with the exclude code switched\r
+off so that I was comparing the creation of the same threads. Sorry if I\r
+didn't make that clear.\r
+\r
+> > /* Specify the sorting desired for this query. */\r
+> > void\r
+> > notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort);\r
+> > @@ -895,7 +900,8 @@ notmuch_message_get_filenames (notmuch_message_t *message);\r
+> > \r
+> > /* Message flags */\r
+> > typedef enum _notmuch_message_flag {\r
+> > - NOTMUCH_MESSAGE_FLAG_MATCH\r
+> > + NOTMUCH_MESSAGE_FLAG_MATCH,\r
+> > + NOTMUCH_MESSAGE_FLAG_EXCLUDED\r
+> > } notmuch_message_flag_t;\r
+> > \r
+> > /* Get a value of a flag for the email corresponding to 'message'. */\r
+> > diff --git a/lib/query.cc b/lib/query.cc\r
+> > index c25b301..7d165d2 100644\r
+> > --- a/lib/query.cc\r
+> > +++ b/lib/query.cc\r
+> > @@ -28,6 +28,7 @@ struct _notmuch_query {\r
+> > const char *query_string;\r
+> > notmuch_sort_t sort;\r
+> > notmuch_string_list_t *exclude_terms;\r
+> > + notmuch_bool_t omit_excluded_messages;\r
+> > };\r
+> > \r
+> > typedef struct _notmuch_mset_messages {\r
+> > @@ -57,6 +58,12 @@ struct visible _notmuch_threads {\r
+> > notmuch_doc_id_set_t match_set;\r
+> > };\r
+> > \r
+> > +/* we need this in the message functions so forward declare */\r
+> \r
+> Comments should start with a capital letter and end with a period.\r
+> (The code isn't completely consistent about this, but it is something\r
+> we're codifying in the upcoming style guide.)\r
+\r
+Will fix\r
+\r
+> > +static notmuch_bool_t\r
+> > +_notmuch_doc_id_set_init (void *ctx,\r
+> > + notmuch_doc_id_set_t *doc_ids,\r
+> > + GArray *arr);\r
+> > +\r
+> > notmuch_query_t *\r
+> > notmuch_query_create (notmuch_database_t *notmuch,\r
+> > const char *query_string)\r
+> > @@ -79,6 +86,8 @@ notmuch_query_create (notmuch_database_t *notmuch,\r
+> > \r
+> > query->exclude_terms = _notmuch_string_list_create (query);\r
+> > \r
+> > + query->omit_excluded_messages = FALSE;\r
+> > +\r
+> > return query;\r
+> > }\r
+> > \r
+> > @@ -89,6 +98,12 @@ notmuch_query_get_query_string (notmuch_query_t *query)\r
+> > }\r
+> > \r
+> > void\r
+> > +notmuch_query_set_omit_excluded_messages (notmuch_query_t *query, notmuch_bool_t omit)\r
+> > +{\r
+> > + query->omit_excluded_messages = omit;\r
+> > +}\r
+> > +\r
+> > +void\r
+> > notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort)\r
+> > {\r
+> > query->sort = sort;\r
+> > @@ -173,6 +188,7 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
+> > "mail"));\r
+> > Xapian::Query string_query, final_query, exclude_query;\r
+> > Xapian::MSet mset;\r
+> > + Xapian::MSetIterator iterator;\r
+> > unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |\r
+> > Xapian::QueryParser::FLAG_PHRASE |\r
+> > Xapian::QueryParser::FLAG_LOVEHATE |\r
+> > @@ -190,11 +206,35 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
+> > final_query = Xapian::Query (Xapian::Query::OP_AND,\r
+> > mail_query, string_query);\r
+> > }\r
+> > + messages->base.excluded_doc_ids = NULL;\r
+> > +\r
+> > + if (query->exclude_terms) {\r
+> > + exclude_query = _notmuch_exclude_tags (query, final_query);\r
+> > + exclude_query = Xapian::Query (Xapian::Query::OP_AND,\r
+> > + exclude_query, final_query);\r
+> > +\r
+> > + if (query->omit_excluded_messages)\r
+> > + final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
+> > + final_query, exclude_query);\r
+> > + else {\r
+> > + enquire.set_weighting_scheme (Xapian::BoolWeight());\r
+> > + enquire.set_query (exclude_query);\r
+> > +\r
+> > + mset = enquire.get_mset (0, notmuch->xapian_db->get_doccount ());\r
+> > +\r
+> > + GArray *excluded_doc_ids = g_array_new (FALSE, FALSE, sizeof (unsigned int));\r
+> > +\r
+> > + for (iterator = mset.begin (); iterator != mset.end (); iterator++)\r
+> > + {\r
+> \r
+> No newline before the brace.\r
+\r
+Will fix.\r
+\r
+> \r
+> > + unsigned int doc_id = *iterator;\r
+> > + g_array_append_val (excluded_doc_ids, doc_id);\r
+> > + }\r
+> > + messages->base.excluded_doc_ids = talloc (query, _notmuch_doc_id_set);\r
+> > + _notmuch_doc_id_set_init (query, messages->base.excluded_doc_ids,\r
+> > + excluded_doc_ids);\r
+> \r
+> Don't forget to g_array_unref excluded_doc_ids.\r
+\r
+Yes I will add that.\r
+\r
+> > + }\r
+> > + }\r
+> > \r
+> > - exclude_query = _notmuch_exclude_tags (query, final_query);\r
+> > -\r
+> > - final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
+> > - final_query, exclude_query);\r
+> > \r
+> > enquire.set_weighting_scheme (Xapian::BoolWeight());\r
+> > \r
+> > @@ -283,6 +323,10 @@ _notmuch_mset_messages_get (notmuch_messages_t *messages)\r
+> > INTERNAL_ERROR ("a messages iterator contains a non-existent document ID.\n");\r
+> > }\r
+> > \r
+> > + if ((messages->excluded_doc_ids) &&\r
+> > + (_notmuch_doc_id_set_contains (messages->excluded_doc_ids, doc_id)))\r
+> \r
+> No need for so many parens (just a nit).\r
+\r
+Will fix.\r
+\r
+> > + notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, TRUE);\r
+> > +\r
+> > return message;\r
+> > }\r
+> > \r
+\r
+Thanks\r
+\r
+Mark\r
+\r