From: Eric Wong Date: Thu, 6 Mar 2025 20:34:41 +0000 (+0000) Subject: xap_helper: drop qp_extra_done flag and conditions X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c8956d5704bd3bebe69000b6fc7d06e68de2c0db;p=thirdparty%2Fpublic-inbox.git xap_helper: drop qp_extra_done flag and conditions As with -d (directories), the -Q (extra query prefixes) flag is already part of the cache key so there's no need to initialize it lazily. While we're at it, drop a `map' op from the cache key generation for the Perl implementation. --- diff --git a/lib/PublicInbox/XapHelper.pm b/lib/PublicInbox/XapHelper.pm index e98553c87..8f3e7e848 100644 --- a/lib/PublicInbox/XapHelper.pm +++ b/lib/PublicInbox/XapHelper.pm @@ -186,16 +186,15 @@ sub cmd_mset { # to be used by WWW + IMAP } } -sub srch_init_extra ($) { - my ($req) = @_; - my $qp = $req->{srch}->{qp}; +sub srch_init_extra ($$) { + my ($srch, $req) = @_; + my $qp = $srch->{qp}; for (@{$req->{Q}}) { my ($upfx, $m, $xpfx) = split /([:=])/; $xpfx // die "E: bad -Q $_"; $m = $m eq '=' ? 'add_boolean_prefix' : 'add_prefix'; $qp->$m($upfx, $xpfx); } - $req->{srch}->{qp_extra_done} = 1; } sub dispatch { @@ -205,7 +204,7 @@ sub dispatch { or return; my $dirs = delete $req->{d} or die 'no -d args'; my $key = "-d\0".join("\0-d\0", @$dirs); - $key .= "\0".join("\0", map { ('-Q', $_) } @{$req->{Q}}) if $req->{Q}; + $key .= "\0-Q\0".join("\0-Q\0", @{$req->{Q}}) if $req->{Q}; my $new; $req->{srch} = $SRCH{$key} // do { $new = { qp_flags => $QP_FLAGS }; @@ -240,11 +239,10 @@ sub dispatch { bless $new, $req->{c} ? 'PublicInbox::CodeSearch' : 'PublicInbox::Search'; $new->qparse_new; + srch_init_extra $new, $req; $SRCH{$key} = $new; }; $req->{srch}->{xdb}->reopen unless $new; - $req->{Q} && !$req->{srch}->{qp_extra_done} and - srch_init_extra $req; my $timeo = $req->{K}; alarm($timeo) if $timeo; $fn->($req, @argv); diff --git a/lib/PublicInbox/xap_helper.h b/lib/PublicInbox/xap_helper.h index f6da52fb7..fd52a70d6 100644 --- a/lib/PublicInbox/xap_helper.h +++ b/lib/PublicInbox/xap_helper.h @@ -120,7 +120,6 @@ static void *xreallocarray(void *ptr, size_t nmemb, size_t size) struct srch { int ckey_len; // int for comparisons unsigned qp_flags; - bool qp_extra_done; Xapian::Database *db; Xapian::QueryParser *qp; unsigned char ckey[]; // $shard_path0\0$shard_path1\0... @@ -594,6 +593,30 @@ static void srch_cache_renew(struct srch *keep) #include "xh_date.h" // GitDateRangeProcessor + GitDateFieldProcessor #include "xh_thread_fp.h" // ThreadFieldProcessor +// setup query parser for altid and arbitrary headers +static void srch_init_extra(struct srch *srch, struct req *req) +{ + const char *XPFX; + for (int i = 0; i < req->qpfxc; i++) { + size_t len = strlen(req->qpfxv[i]); + char *c = (char *)memchr(req->qpfxv[i], '=', len); + + if (c) { // it's boolean "gmane=XGMANE" + XPFX = c + 1; + *c = 0; + srch->qp->add_boolean_prefix(req->qpfxv[i], XPFX); + continue; + } + // maybe it's a non-boolean prefix "blob:XBLOBID" + c = (char *)memchr(req->qpfxv[i], ':', len); + if (!c) + errx(EXIT_FAILURE, "bad -Q %s", req->qpfxv[i]); + XPFX = c + 1; + *c = 0; + srch->qp->add_prefix(req->qpfxv[i], XPFX); + } +} + static void srch_init(struct req *req) { int i; @@ -659,31 +682,7 @@ static void srch_init(struct req *req) srch->qp->add_boolean_prefix("L", "L"); } } -} - -// setup query parser for altid and arbitrary headers -static void srch_init_extra(struct req *req) -{ - const char *XPFX; - for (int i = 0; i < req->qpfxc; i++) { - size_t len = strlen(req->qpfxv[i]); - char *c = (char *)memchr(req->qpfxv[i], '=', len); - - if (c) { // it's boolean "gmane=XGMANE" - XPFX = c + 1; - *c = 0; - req->srch->qp->add_boolean_prefix(req->qpfxv[i], XPFX); - continue; - } - // maybe it's a non-boolean prefix "blob:XBLOBID" - c = (char *)memchr(req->qpfxv[i], ':', len); - if (!c) - errx(EXIT_FAILURE, "bad -Q %s", req->qpfxv[i]); - XPFX = c + 1; - *c = 0; - req->srch->qp->add_prefix(req->qpfxv[i], XPFX); - } - req->srch->qp_extra_done = true; + srch_init_extra(req->srch, req); } #define OPT_U(ch, var, fn, max) do { \ @@ -764,7 +763,6 @@ static void dispatch(struct req *req) ERR_CLOSE(kfp, EXIT_FAILURE); // may ENOMEM, sets kbuf.srch kbuf.srch->db = NULL; kbuf.srch->qp = NULL; - kbuf.srch->qp_extra_done = false; kbuf.srch->ckey_len = size - offsetof(struct srch, ckey); if (kbuf.srch->ckey_len <= 0 || !req->dirc) ABORT("no -d args (or too many)"); @@ -780,8 +778,6 @@ static void dispatch(struct req *req) srch_free(kbuf.srch); req->srch->db->reopen(); } - if (req->qpfxc && !req->srch->qp_extra_done) - srch_init_extra(req); if (req->timeout_sec) alarm(req->timeout_sec > UINT_MAX ? UINT_MAX : (unsigned)req->timeout_sec);