From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH 2/5] *search: favor wantarray form of xap_terms
Date: Thu, 7 Dec 2023 11:42:43 +0000 [thread overview]
Message-ID: <20231207114246.3614375-2-e@80x24.org> (raw)
In-Reply-To: <20231207114246.3614375-1-e@80x24.org>
Most xap_terms callers do not benefit from the hashref
return value, and we can delay hashmap use until
List::Util::uniqstr if needed.
---
lib/PublicInbox/CodeSearch.pm | 15 ++++++---------
lib/PublicInbox/LeiSearch.pm | 17 +++++++----------
lib/PublicInbox/LeiStore.pm | 13 +++++++------
3 files changed, 20 insertions(+), 25 deletions(-)
diff --git a/lib/PublicInbox/CodeSearch.pm b/lib/PublicInbox/CodeSearch.pm
index 3092718d..48697cdc 100644
--- a/lib/PublicInbox/CodeSearch.pm
+++ b/lib/PublicInbox/CodeSearch.pm
@@ -9,6 +9,7 @@ use v5.12;
use parent qw(PublicInbox::Search);
use PublicInbox::Config;
use PublicInbox::Search qw(retry_reopen int_val xap_terms);
+use PublicInbox::Compat qw(uniqstr);
use Compress::Zlib qw(uncompress);
use constant {
AT => 0, # author time YYYYMMDDHHMMSS, dt: for mail)
@@ -199,12 +200,11 @@ sub roots2paths { # for diagnostics
do {
my $mset = $enq->get_mset($off += $size, $lim);
for my $x ($mset->items) {
- my $tmp = xap_terms('P', $x->get_document);
- push @$dirs, keys %$tmp;
+ push @$dirs, xap_terms('P', $x->get_document);
}
$size = $mset->size;
} while ($size);
- @$dirs = sort @$dirs;
+ @$dirs = sort(uniqstr(@$dirs));
}
\%ret;
}
@@ -223,12 +223,9 @@ sub root_oids ($$) {
my @ids = docids_of_git_dir $self, $git_dir or warn <<"";
BUG? (non-fatal) `$git_dir' not indexed in $self->{topdir}
- my %ret;
- for my $docid (@ids) {
- my @oids = xap_terms('G', $self->xdb, $docid);
- @ret{@oids} = @oids;
- }
- sort keys %ret;
+ my @ret = map { xap_terms('G', $self->xdb, $_) } @ids;
+ @ret = uniqstr(@ret) if @ids > 1;
+ @ret;
}
sub paths2roots {
diff --git a/lib/PublicInbox/LeiSearch.pm b/lib/PublicInbox/LeiSearch.pm
index ba4c4309..29e3213f 100644
--- a/lib/PublicInbox/LeiSearch.pm
+++ b/lib/PublicInbox/LeiSearch.pm
@@ -9,6 +9,7 @@ use parent qw(PublicInbox::ExtSearch); # PublicInbox::Search->reopen
use PublicInbox::Search qw(xap_terms);
use PublicInbox::ContentHash qw(content_digest content_hash git_sha);
use PublicInbox::MID qw(mids mids_for_index);
+use PublicInbox::Compat qw(uniqstr);
use Carp qw(croak);
sub _msg_kw { # retry_reopen callback
@@ -44,20 +45,16 @@ sub oidbin_keywords {
sub _xsmsg_vmd { # retry_reopen
my ($self, $smsg, $want_label) = @_;
my $xdb = $self->xdb; # set {nshard};
- my (%kw, %L, $doc, $x);
- $kw{flagged} = 1 if delete($smsg->{lei_q_tt_flagged});
+ my (@kw, @L, $doc, $x);
+ @kw = qw(flagged) if delete($smsg->{lei_q_tt_flagged});
my @num = $self->over->blob_exists($smsg->{blob});
for my $num (@num) { # there should only be one...
$doc = $xdb->get_document($self->num2docid($num));
- $x = xap_terms('K', $doc);
- %kw = (%kw, %$x);
- if ($want_label) { # JSON/JMAP only
- $x = xap_terms('L', $doc);
- %L = (%L, %$x);
- }
+ push @kw, xap_terms('K', $doc);
+ push @L, xap_terms('L', $doc) if $want_label # JSON/JMAP only
}
- $smsg->{kw} = [ sort keys %kw ] if scalar(keys(%kw));
- $smsg->{L} = [ sort keys %L ] if scalar(keys(%L));
+ @{$smsg->{kw}} = sort(uniqstr(@kw)) if @kw;
+ @{$smsg->{L}} = uniqstr(@L) if @L;
}
# lookup keywords+labels for external messages
diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm
index aebb85a9..a752174d 100644
--- a/lib/PublicInbox/LeiStore.pm
+++ b/lib/PublicInbox/LeiStore.pm
@@ -27,6 +27,7 @@ use PublicInbox::MDA;
use PublicInbox::Spawn qw(spawn);
use PublicInbox::MdirReader;
use PublicInbox::LeiToMail;
+use PublicInbox::Compat qw(uniqstr);
use File::Temp qw(tmpnam);
use POSIX ();
use IO::Handle (); # ->autoflush
@@ -341,15 +342,15 @@ sub _add_vmd ($$$$) {
sub _docids_and_maybe_kw ($$) {
my ($self, $docids) = @_;
return $docids unless wantarray;
- my $kw = {};
+ my (@kw, $idx, @tmp);
for my $num (@$docids) { # likely only 1, unless ContentHash changes
# can't use ->search->msg_keywords on uncommitted docs
- my $idx = $self->{priv_eidx}->idx_shard($num);
- my $tmp = eval { $idx->ipc_do('get_terms', 'K', $num) };
- if ($@) { warn "#$num get_terms: $@" }
- else { @$kw{keys %$tmp} = values(%$tmp) };
+ $idx = $self->{priv_eidx}->idx_shard($num);
+ @tmp = eval { $idx->ipc_do('get_terms', 'K', $num) };
+ $@ ? warn("#$num get_terms: $@") : push(@kw, @tmp);
}
- ($docids, [ sort keys %$kw ]);
+ @kw = sort(uniqstr(@kw)) if @$docids > 1;
+ ($docids, \@kw);
}
sub _reindex_1 { # git->cat_async callback
next prev parent reply other threads:[~2023-12-07 11:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-07 11:42 [PATCH 1/5] *search: simplify handling of Xapian term iterators Eric Wong
2023-12-07 11:42 ` Eric Wong [this message]
2023-12-07 11:42 ` [PATCH 3/5] xap_helper_cxx: drop chdir usage in build Eric Wong
2023-12-07 11:42 ` [PATCH 4/5] makefile: add `check-build' target Eric Wong
2023-12-07 11:42 ` [PATCH 5/5] xap_helper: support term length limit 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231207114246.3614375-2-e@80x24.org \
--to=e@80x24.org \
--cc=spew@80x24.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).