From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [PATCH 2/4] lib/query: make query parsing lazy again, keep centralized.
Date: Sat, 18 Feb 2017 11:08:02 -0400 [thread overview]
Message-ID: <20170218150804.26704-3-david@tethera.net> (raw)
In-Reply-To: <20170218150804.26704-1-david@tethera.net>
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 0787c56b..6f6519d7 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,22 +108,33 @@ 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);
- talloc_free (query);
- query = NULL;
+ return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
}
-
- return query;
+ return NOTMUCH_STATUS_SUCCESS;
}
const char *
@@ -225,6 +238,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))
@@ -591,6 +609,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
next prev parent reply other threads:[~2017-02-18 15:08 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-18 15:08 v4 of nondestructive excludes patches David Bremner
2017-02-18 15:08 ` [PATCH 1/4] lib: eagerly parse queries David Bremner
2017-02-18 15:08 ` David Bremner [this message]
2017-02-18 15:08 ` [PATCH 3/4] lib: query make exclude handling non-destructive David Bremner
2017-02-18 15:08 ` [PATCH 4/4] lib: make notmuch_query_add_tag_exclude return a status value David Bremner
2017-03-22 11:54 ` David Bremner
2017-02-25 16:09 ` v5 of nondestructive includes patches David Bremner
2017-02-25 16:09 ` [PATCH 1/3] lib: eagerly parse queries David Bremner
2017-02-25 16:09 ` [PATCH 2/3] lib/query: make query parsing lazy again, keep centralized David Bremner
2017-02-25 16:09 ` [PATCH 3/3] lib: query make exclude handling non-destructive David Bremner
-- strict thread matches above, loose matches on Subject: below --
2016-11-22 2:27 V3 of non-destructive excludes patches David Bremner
2016-11-22 2:27 ` [PATCH 2/4] lib/query: make query parsing lazy again, keep centralized David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170218150804.26704-3-david@tethera.net \
--to=david@tethera.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).