From: Eric Wong Date: Wed, 5 Mar 2025 07:18:35 +0000 (+0000) Subject: xap_helper.h: share ThreadFieldProcessor across DBs X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3a0ce010b2456a2611fd5e1cfb4df477bb84f2e;p=thirdparty%2Fpublic-inbox.git xap_helper.h: share ThreadFieldProcessor across DBs Unlike notmuch, we don't actually use the QueryParser from initialization and can stop storing it in the class. Instead, we rely on the global `cur_srch' at runtime for both which has both the Xapian::Databaase and Xapian::QueryParser objects. So stop carrying a copy of the ThreadFieldProcessor object for every DB connection we have since some public non-extindex-users may have many DBs and we can probably save some memory this way. --- diff --git a/lib/PublicInbox/xap_helper.h b/lib/PublicInbox/xap_helper.h index 1bb08badf..816f7df50 100644 --- a/lib/PublicInbox/xap_helper.h +++ b/lib/PublicInbox/xap_helper.h @@ -156,6 +156,7 @@ static unsigned long nworker, nworker_hwm; static int pipefds[2]; static const char *stdout_path, *stderr_path; // for SIGUSR1 static sig_atomic_t worker_needs_reopen; +static Xapian::FieldProcessor *thread_fp; // PublicInbox::Search and PublicInbox::CodeSearch generate these: static void mail_rp_init(void); @@ -650,12 +651,8 @@ static void srch_init(struct req *req) if (req->code_search) { qp_init_code_search(srch->qp); // CodeSearch.pm } else { - Xapian::FieldProcessor *fp; - qp_init_mail_search(srch->qp); // Search.pm - // n.b. ->release() starts Xapian refcounting - fp = (new ThreadFieldProcessor(*srch->qp))->release(); - srch->qp->add_boolean_prefix("thread", fp); + srch->qp->add_boolean_prefix("thread", thread_fp); } } @@ -1086,6 +1083,7 @@ int main(int argc, char *argv[]) warnx("W: RLIMIT_NOFILE=%ld too low\n", my_fd_max); my_fd_max -= 64; + thread_fp = new ThreadFieldProcessor(); xh_date_init(); mail_rp_init(); code_nrp_init(); diff --git a/lib/PublicInbox/xh_thread_fp.h b/lib/PublicInbox/xh_thread_fp.h index 8f0385f14..ccded18c3 100644 --- a/lib/PublicInbox/xh_thread_fp.h +++ b/lib/PublicInbox/xh_thread_fp.h @@ -3,10 +3,7 @@ // Disclaimer: Eric doesn't know C++ class ThreadFieldProcessor : public Xapian::FieldProcessor { -protected: - Xapian::QueryParser &qp; public: - ThreadFieldProcessor(Xapian::QueryParser &qp_) : qp(qp_) {}; Xapian::Query operator()(const std::string &str); };