From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] xap_helper: unconditionally reopen DBs on reuse
Date: Tue, 7 May 2024 19:14:27 +0000 [thread overview]
Message-ID: <20240507191427.2038001-1-e@80x24.org> (raw)
Reopening Xapian DBs is a fairly cheap operation and Xapian
avoids doing work when nothing's changed, so just do it
to ensure we always get the latest updates in search results.
The old synchronous search interface worked around this by
having a timer based expiration in hopes of mitigating
fragmentation problems, but perhaps that's not worth doing
anymore now that memory fragmentation from Perl itself is
better understood.
---
lib/PublicInbox/XapHelper.pm | 4 +++-
lib/PublicInbox/xap_helper.h | 1 +
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/PublicInbox/XapHelper.pm b/lib/PublicInbox/XapHelper.pm
index 099bc4fe..c9957f64 100644
--- a/lib/PublicInbox/XapHelper.pm
+++ b/lib/PublicInbox/XapHelper.pm
@@ -191,8 +191,9 @@ sub dispatch {
or return;
my $dirs = delete $req->{d} or die 'no -d args';
my $key = join("\0", @$dirs);
+ my $new;
$req->{srch} = $SRCH{$key} //= do {
- my $new = { qp_flags => $PublicInbox::Search::QP_FLAGS };
+ $new = { qp_flags => $PublicInbox::Search::QP_FLAGS };
my $first = shift @$dirs;
my $slow_phrase = -f "$first/iamchert";
$new->{xdb} = $X->{Database}->new($first);
@@ -207,6 +208,7 @@ sub dispatch {
$new->{qp} = $new->qparse_new;
$new;
};
+ $req->{srch}->{xdb}->reopen unless $new;
$req->{Q} && !$req->{srch}->{qp_extra_done} and
srch_init_extra $req;
my $timeo = $req->{K};
diff --git a/lib/PublicInbox/xap_helper.h b/lib/PublicInbox/xap_helper.h
index bdc1c5b1..a30a8768 100644
--- a/lib/PublicInbox/xap_helper.h
+++ b/lib/PublicInbox/xap_helper.h
@@ -712,6 +712,7 @@ static void dispatch(struct req *req)
req->srch = *s;
if (req->srch != kbuf.srch) { // reuse existing
free_srch(kbuf.srch);
+ req->srch->db->reopen();
} else if (!srch_init(req)) {
assert(kbuf.srch == *((struct srch **)tfind(
kbuf.srch, &srch_tree, srch_cmp)));
reply other threads:[~2024-05-07 19:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240507191427.2038001-1-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.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.
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).