]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
xap_helper: unconditionally reopen DBs on reuse
authorEric Wong <e@80x24.org>
Tue, 7 May 2024 19:14:27 +0000 (19:14 +0000)
committerEric Wong <e@80x24.org>
Wed, 8 May 2024 06:00:01 +0000 (06:00 +0000)
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
lib/PublicInbox/xap_helper.h

index 099bc4fe33e00a256df5c6be1c5b24f7f5afb1d1..c9957f64511adf51adcd44bedae77e1420fffeb4 100644 (file)
@@ -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};
index bdc1c5b1238b9954f6381b10e03ded294ab61b51..a30a8768a432a485dcb9e0d31688619659108480 100644 (file)
@@ -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)));