]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
xap_helper.h: share ThreadFieldProcessor across DBs
authorEric Wong <e@80x24.org>
Wed, 5 Mar 2025 07:18:35 +0000 (07:18 +0000)
committerEric Wong <e@80x24.org>
Fri, 7 Mar 2025 19:23:13 +0000 (19:23 +0000)
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.

lib/PublicInbox/xap_helper.h
lib/PublicInbox/xh_thread_fp.h

index 1bb08badf2519d132932c4af491fde49a7203123..816f7df5095d6cf7e78e78384e17b3f20cd8ca92 100644 (file)
@@ -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();
index 8f0385f14043f0e9f9ec5f049e341478cba892dd..ccded18c3e56181d67daba05344231a7d230d71f 100644 (file)
@@ -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);
 };