From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/2] lei inspect: support "mid:" (and "m:") prefix
Date: Thu, 1 Jul 2021 11:31:33 +0000 [thread overview]
Message-ID: <20210701113133.30648-3-e@80x24.org> (raw)
In-Reply-To: <20210701113133.30648-1-e@80x24.org>
Using this to track down deduplication failures in -extindex...
---
lib/PublicInbox/LeiInspect.pm | 53 +++++++++++++++++++++++++++--------
1 file changed, 42 insertions(+), 11 deletions(-)
diff --git a/lib/PublicInbox/LeiInspect.pm b/lib/PublicInbox/LeiInspect.pm
index 9a7900c7..574da7a7 100644
--- a/lib/PublicInbox/LeiInspect.pm
+++ b/lib/PublicInbox/LeiInspect.pm
@@ -98,22 +98,29 @@ sub inspect_docid ($$;$) {
$ent;
}
+sub dir2ibx ($$) {
+ my ($lei, $dir) = @_;
+ if (-f "$dir/ei.lock") {
+ require PublicInbox::ExtSearch;
+ PublicInbox::ExtSearch->new($dir);
+ } elsif (-f "$dir/inbox.lock" || -d "$dir/public-inbox") {
+ require PublicInbox::Inbox; # v2, v1
+ bless { inboxdir => $dir }, 'PublicInbox::Inbox';
+ } else {
+ $lei->fail("no (indexed) inbox or extindex at $dir");
+ }
+}
+
sub inspect_num ($$) {
my ($lei, $num) = @_;
my ($docid, $ibx);
my $ent = { num => $num };
if (defined(my $dir = $lei->{opt}->{dir})) {
- my $num2docid = $lei->{lse}->can('num2docid');
- if (-f "$dir/ei.lock") {
- require PublicInbox::ExtSearch;
- $ibx = PublicInbox::ExtSearch->new($dir);
- } elsif (-f "$dir/inbox.lock" || -d "$dir/public-inbox") {
- require PublicInbox::Inbox; # v2, v1
- $ibx = bless { inboxdir => $dir }, 'PublicInbox::Inbox';
+ $ibx = dir2ibx($lei, $dir) or return;
+ if ($ent->{xdb} = $ibx->xdb) {
+ my $num2docid = $lei->{lse}->can('num2docid');
+ $docid = $num2docid->($ibx, $num);
}
- $ent->{xdb} = $ibx->xdb //
- return $lei->fail("no Xapian DB for $dir");
- $docid = $num2docid->($ibx, $num);
} else {
$ibx = $lei->{lse};
$lei->{lse}->xdb; # set {nshard} for num2docid
@@ -123,7 +130,29 @@ sub inspect_num ($$) {
my $smsg = $ibx->over->get_art($num);
$ent->{smsg} = { %$smsg } if $smsg;
}
- inspect_docid($lei, $docid, $ent);
+ defined($docid) ? inspect_docid($lei, $docid, $ent) : $ent;
+}
+
+sub inspect_mid ($$) {
+ my ($lei, $mid) = @_;
+ my ($ibx, $over);
+ my $ent = { mid => $mid };
+ if (defined(my $dir = $lei->{opt}->{dir})) {
+ my $num2docid = $lei->{lse}->can('num mid => [ $mid ] 2docid');
+ $ibx = dir2ibx($lei, $dir) or return;
+ # $ent->{xdb} = $ibx->xdb //
+ # return $lei->fail("no Xapian DB for $dir");
+ } else {
+ $ibx = $lei->{lse};
+ $lei->{lse}->xdb; # set {nshard} for num2docid
+ }
+ if ($ibx && $ibx->over) {
+ my ($id, $prev);
+ while (my $smsg = $ibx->over->next_by_mid($mid, \$id, \$prev)) {
+ push @{$ent->{smsg}}, { %$smsg }
+ }
+ }
+ $ent;
}
sub inspect1 ($$$) {
@@ -145,6 +174,8 @@ sub inspect1 ($$$) {
$ent = inspect_docid($lei, $1 + 0);
} elsif ($item =~ m!\Anum:([0-9]+)\z!) {
$ent = inspect_num($lei, $1 + 0);
+ } elsif ($item =~ m!\A(?:mid|m):(.+)\z!) {
+ $ent = inspect_mid($lei, $1);
} else { # TODO: more things
return $lei->fail("$item not understood");
}
prev parent reply other threads:[~2021-07-01 11:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-01 11:31 [PATCH 0/2] lei inspect: "mid:" prefix and pager Eric Wong
2021-07-01 11:31 ` [PATCH 1/2] lei inspect: support automatic pager in output Eric Wong
2021-07-01 11:31 ` Eric Wong [this message]
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=20210701113133.30648-3-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).