From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id D1AB96DE1B46 for ; Sat, 25 Feb 2017 08:09:25 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.005 X-Spam-Level: X-Spam-Status: No, score=-0.005 tagged_above=-999 required=5 tests=[AWL=0.006, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zBX4MgZobwvz for ; Sat, 25 Feb 2017 08:09:25 -0800 (PST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id B68286DE1B4C for ; Sat, 25 Feb 2017 08:09:24 -0800 (PST) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1chetq-0006Di-3F; Sat, 25 Feb 2017 11:08:46 -0500 Received: (nullmailer pid 22936 invoked by uid 1000); Sat, 25 Feb 2017 16:09:20 -0000 From: David Bremner To: David Bremner , notmuch@notmuchmail.org Subject: [PATCH 2/3] lib/query: make query parsing lazy again, keep centralized. Date: Sat, 25 Feb 2017 12:09:12 -0400 Message-Id: <20170225160913.22844-3-david@tethera.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170225160913.22844-1-david@tethera.net> References: <20170218150804.26704-1-david@tethera.net> <20170225160913.22844-1-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.22 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, 25 Feb 2017 16:09:25 -0000 This is mainly to fix the nasty error path introduced in the last commit, by moving the parsing into functions where the API is already set up to return error status. It preserves the feature of having a pre-parsed query available for further processing. --- lib/query.cc | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/query.cc b/lib/query.cc index 3cf63fc9..bab8a60f 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -29,6 +29,7 @@ struct _notmuch_query { notmuch_sort_t sort; notmuch_string_list_t *exclude_terms; notmuch_exclude_t omit_excluded; + notmuch_bool_t parsed; Xapian::Query xapian_query; }; @@ -93,6 +94,7 @@ notmuch_query_create (notmuch_database_t *notmuch, return NULL; new (&query->xapian_query) Xapian::Query (); + query->parsed = FALSE; talloc_set_destructor (query, _notmuch_query_destructor); @@ -106,23 +108,34 @@ notmuch_query_create (notmuch_database_t *notmuch, query->omit_excluded = NOTMUCH_EXCLUDE_TRUE; + return query; +} + +static notmuch_status_t +_notmuch_query_ensure_parsed (notmuch_query_t *query) +{ + if (query->parsed) + return NOTMUCH_STATUS_SUCCESS; + try { query->xapian_query = - notmuch->query_parser->parse_query (query_string, NOTMUCH_QUERY_PARSER_FLAGS); + query->notmuch->query_parser-> + parse_query (query->query_string, NOTMUCH_QUERY_PARSER_FLAGS); + + query->parsed = TRUE; + } catch (const Xapian::Error &error) { - _notmuch_database_log (notmuch, + _notmuch_database_log (query->notmuch, "A Xapian exception occured parsing query: %s\n", error.get_msg().c_str()); - _notmuch_database_log_append (notmuch, + _notmuch_database_log_append (query->notmuch, "Query string was: %s\n", query->query_string); query->notmuch->exception_reported = TRUE; - talloc_free (query); - query = NULL; + return NOTMUCH_STATUS_XAPIAN_EXCEPTION; } - - return query; + return NOTMUCH_STATUS_SUCCESS; } const char * @@ -226,6 +239,11 @@ _notmuch_query_search_documents (notmuch_query_t *query, notmuch_database_t *notmuch = query->notmuch; const char *query_string = query->query_string; notmuch_mset_messages_t *messages; + notmuch_status_t status; + + status = _notmuch_query_ensure_parsed (query); + if (status) + return status; messages = talloc (query, notmuch_mset_messages_t); if (unlikely (messages == NULL)) @@ -592,6 +610,11 @@ _notmuch_query_count_documents (notmuch_query_t *query, const char *type, unsign notmuch_database_t *notmuch = query->notmuch; const char *query_string = query->query_string; Xapian::doccount count = 0; + notmuch_status_t status; + + status = _notmuch_query_ensure_parsed (query); + if (status) + return status; try { Xapian::Enquire enquire (*notmuch->xapian_db); -- 2.11.0