From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/2] xap_helper: drop qp_extra_done flag and conditions
Date: Thu, 6 Mar 2025 20:34:41 +0000 [thread overview]
Message-ID: <20250306203442.724380-2-e@80x24.org> (raw)
In-Reply-To: <20250306203442.724380-1-e@80x24.org>
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.
---
lib/PublicInbox/XapHelper.pm | 12 ++++----
lib/PublicInbox/xap_helper.h | 54 +++++++++++++++++-------------------
2 files changed, 30 insertions(+), 36 deletions(-)
diff --git a/lib/PublicInbox/XapHelper.pm b/lib/PublicInbox/XapHelper.pm
index e98553c8..8f3e7e84 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 f6da52fb..fd52a70d 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);
next prev parent reply other threads:[~2025-03-06 20:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-06 20:34 [PATCH 0/2] Perl XapHelper fix + cleanup Eric Wong
2025-03-06 20:34 ` Eric Wong [this message]
2025-03-06 20:34 ` [PATCH 2/2] XapHelper.pm: fix QP_FLAGS initialization Eric Wong
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=20250306203442.724380-2-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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
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).