From c6a4e8f9ad7b864074b507d811a8120f57f45e2c Mon Sep 17 00:00:00 2001 From: djcb Date: Thu, 27 Dec 2012 11:09:05 +0200 Subject: [PATCH] * mu-query: re-introduce MU_QUERY_FLAG_THREADS, and only calculate threads for the _second_ query when doing an --include-related query --- lib/mu-query.cc | 25 +++++++++++++++++++++---- lib/mu-query.h | 5 +++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/mu-query.cc b/lib/mu-query.cc index d82eced0..4f1fd888 100644 --- a/lib/mu-query.cc +++ b/lib/mu-query.cc @@ -370,6 +370,8 @@ msg_iter_flags (MuQueryFlags flags) iflags |= MU_MSG_ITER_FLAG_SKIP_UNREADABLE; if (flags & MU_QUERY_FLAG_SKIP_DUPS) iflags |= MU_MSG_ITER_FLAG_SKIP_DUPS; + if (flags & MU_QUERY_FLAG_THREADS) + iflags |= MU_MSG_ITER_FLAG_THREADS; return iflags; } @@ -478,23 +480,38 @@ mu_query_run (MuQuery *self, const char *searchexpr, MuMsgFieldId sortfieldid, NULL); try { MuMsgIter *iter; - bool descending = flags & MU_QUERY_FLAG_DESCENDING; + MuQueryFlags first_flags; + bool inc_related = flags & MU_QUERY_FLAG_INCLUDE_RELATED; + bool descending = flags & MU_QUERY_FLAG_DESCENDING; Xapian::Enquire enq (get_enquire(self, searchexpr, sortfieldid, descending, err)); + /* when we're doing a 'include-related query', we're + * actually doing /two/ queries; one to get the + * initial matches, and based on that one to get all + * messages in threads in those matches. + */ + /* get the 'real' maxnum if it was specified as < 0 */ - maxnum = maxnum <= 0 ? self->db().get_doccount() : maxnum; + maxnum = maxnum < 0 ? self->db().get_doccount() : maxnum; + /* if we do a include-related query, it's wasted + * effort to calculate threads already in the first + * query since we can do it in the second one + */ + first_flags = inc_related ? (flags & ~MU_QUERY_FLAG_THREADS) : flags; + iter = mu_msg_iter_new ( reinterpret_cast(&enq), maxnum, sortfieldid, - msg_iter_flags (flags), + msg_iter_flags (first_flags), err); + /* * if we want related messages, do a second query, * based on the message ids / refs of the first one * */ - if (flags & MU_QUERY_FLAG_INCLUDE_RELATED) + if (inc_related) include_related (self, &iter, maxnum, sortfieldid, flags); if (err && *err && (*err)->code == MU_ERROR_XAPIAN_MODIFIED) { diff --git a/lib/mu-query.h b/lib/mu-query.h index 2299038b..927235dc 100644 --- a/lib/mu-query.h +++ b/lib/mu-query.h @@ -71,9 +71,10 @@ enum _MuQueryFlags { MU_QUERY_FLAG_DESCENDING = 1 << 0, /**< sort z->a */ MU_QUERY_FLAG_SKIP_UNREADABLE = 1 << 1, /**< skip unreadable msgs */ MU_QUERY_FLAG_SKIP_DUPS = 1 << 2, /**< skip duplicate msgs */ - MU_QUERY_FLAG_INCLUDE_RELATED = 1 << 3 /**< include related msgs */ + MU_QUERY_FLAG_INCLUDE_RELATED = 1 << 3, /**< include related msgs */ + MU_QUERY_FLAG_THREADS = 1 << 4 /**< calculate threading info */ }; -typedef enum _MuQueryFlags MuQueryFlags; +typedef int MuQueryFlags; /** * run a Xapian query; for the syntax, please refer to the mu-find