From 62bf89ba6fd691d27964666546dfd7403ec37e81 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 23 Feb 2025 13:13:34 +0000 Subject: [PATCH] xap_helper: avoid temporary std::set in thread fp Instead of creating a temporary std::set to store THREADIDs, just inject the Xapian::Query::OP_OR operations directly into the query we return. Unlike notmuch(1), we can do this without risking redundant query ops from repeated THREADIDs since use since we use a column instead of a term for THREADID. Column use allowed us to use .set_collapse_key to deduplicate the intermediate mset, already. --- lib/PublicInbox/xh_thread_fp.h | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/PublicInbox/xh_thread_fp.h b/lib/PublicInbox/xh_thread_fp.h index 2c88401c8..27b5cfcb5 100644 --- a/lib/PublicInbox/xh_thread_fp.h +++ b/lib/PublicInbox/xh_thread_fp.h @@ -10,13 +10,17 @@ public: Xapian::Query operator()(const std::string &str); }; -static enum exc_iter xpand_col_iter(std::set &vals, +static enum exc_iter xpand_col_iter(Xapian::Query *xqry, Xapian::MSetIterator *i, unsigned column) { try { Xapian::Document doc = i->get_document(); - vals.insert(doc.get_value(column)); + std::string val = doc.get_value(column); + *xqry = Xapian::Query(Xapian::Query::OP_OR, *xqry, + Xapian::Query( + Xapian::Query::OP_VALUE_RANGE, + column, val, val)); } catch (const Xapian::DatabaseModifiedError &e) { cur_srch->db->reopen(); return ITER_RETRY; @@ -29,9 +33,7 @@ static enum exc_iter xpand_col_iter(std::set &vals, static Xapian::Query qry_xpand_col(Xapian::Query qry, unsigned column) { Xapian::Query xqry = Xapian::Query::MatchNothing; - Xapian::Enquire enq(*cur_srch->db); - std::set vals; // serialised Xapian column enq.set_weighting_scheme(Xapian::BoolWeight()); enq.set_query(qry); @@ -41,19 +43,12 @@ static Xapian::Query qry_xpand_col(Xapian::Query qry, unsigned column) for (Xapian::MSetIterator i = mset.begin(); i != mset.end(); i++) { for (int t = 10; t > 0; --t) - switch (xpand_col_iter(vals, &i, column)) { + switch (xpand_col_iter(&xqry, &i, column)) { case ITER_OK: t = 0; break; // leave inner loop case ITER_RETRY: break; // continue for-loop case ITER_ABORT: return xqry; // impossible } } - - std::set::const_iterator tid; - for (tid = vals.begin(); tid != vals.end(); tid++) - xqry = Xapian::Query(Xapian::Query::OP_OR, xqry, - Xapian::Query( - Xapian::Query::OP_VALUE_RANGE, - column, *tid, *tid)); return xqry; } -- 2.47.3