X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FLeiInspect.pm;h=d7775d4b616203dd682984422352be6f11688906;hb=23af251dd607c4e75ab1e68063f2c885c48cc035;hp=8e1285808fa35a3dd9093bbafa0984a38fac7d6c;hpb=387f0e693f9e22a7698927bb40dab0742738e8a6;p=public-inbox.git diff --git a/lib/PublicInbox/LeiInspect.pm b/lib/PublicInbox/LeiInspect.pm index 8e128580..d7775d4b 100644 --- a/lib/PublicInbox/LeiInspect.pm +++ b/lib/PublicInbox/LeiInspect.pm @@ -12,6 +12,17 @@ use parent qw(PublicInbox::IPC); use PublicInbox::Config; use PublicInbox::MID qw(mids); use PublicInbox::NetReader qw(imap_uri nntp_uri); +use POSIX qw(strftime); +use PublicInbox::LeiOverview; +*iso8601 = \&PublicInbox::LeiOverview::iso8601; + +sub _json_prep ($) { + my ($smsg) = @_; + $smsg->{$_} += 0 for qw(bytes lines); # integerize + $smsg->{dt} = iso8601($smsg->{ds}) if defined($smsg->{ds}); + $smsg->{rt} = iso8601($smsg->{ts}) if defined($smsg->{ts}); + +{ %$smsg } # unbless and scalarize +} sub inspect_blob ($$) { my ($lei, $oidhex) = @_; @@ -72,22 +83,9 @@ sub inspect_sync_folder ($$) { $ent } -sub inspect_docid ($$;$) { - my ($lei, $docid, $ent) = @_; - require PublicInbox::Search; - $ent //= {}; - my $xdb; - if ($xdb = delete $ent->{xdb}) { # from inspect_num - } elsif (defined(my $dir = $lei->{opt}->{dir})) { - no warnings 'once'; - $xdb = $PublicInbox::Search::X{Database}->new($dir); - } else { - $xdb = $lei->{lse}->xdb; - } - $xdb or return $lei->fail('no Xapian DB'); - my $doc = $xdb->get_document($docid); # raises +sub _inspect_doc ($$) { + my ($ent, $doc) = @_; my $data = $doc->get_data; - $ent->{docid} = $docid; $ent->{data_length} = length($data); $ent->{description} = $doc->get_description; $ent->{$_} = $doc->$_ for (qw(termlist_count values_count)); @@ -113,6 +111,24 @@ sub inspect_docid ($$;$) { $ent; } +sub inspect_docid ($$;$) { + my ($lei, $docid, $ent) = @_; + require PublicInbox::Search; + $ent //= {}; + my $xdb; + if ($xdb = delete $ent->{xdb}) { # from inspect_num + } elsif (defined(my $dir = $lei->{opt}->{dir})) { + no warnings 'once'; + $xdb = $PublicInbox::Search::X{Database}->new($dir); + } elsif ($lei->{lse}) { + $xdb = $lei->{lse}->xdb; + } + $xdb or return $lei->fail('no Xapian DB'); + my $doc = $xdb->get_document($docid); # raises + $ent->{docid} = $docid; + _inspect_doc($ent, $doc); +} + sub dir2ibx ($$) { my ($lei, $dir) = @_; if (-f "$dir/ei.lock") { @@ -132,39 +148,43 @@ sub inspect_num ($$) { my $ent = { num => $num }; if (defined(my $dir = $lei->{opt}->{dir})) { $ibx = dir2ibx($lei, $dir) or return; - if ($ent->{xdb} = $ibx->xdb) { - my $num2docid = $lei->{lse}->can('num2docid'); - $docid = $num2docid->($ibx, $num); + if (my $srch = $ibx->search) { + $ent->{xdb} = $srch->xdb and + $docid = $srch->num2docid($num); } - } else { + } elsif ($lei->{lse}) { $ibx = $lei->{lse}; $lei->{lse}->xdb; # set {nshard} for num2docid $docid = $lei->{lse}->num2docid($num); } if ($ibx && $ibx->over) { my $smsg = $ibx->over->get_art($num); - $ent->{smsg} = { %$smsg } if $smsg; + $ent->{smsg} = _json_prep($smsg) if $smsg; } defined($docid) ? inspect_docid($lei, $docid, $ent) : $ent; } sub inspect_mid ($$) { my ($lei, $mid) = @_; - my ($ibx, $over); + my $ibx; 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"); + $ibx = dir2ibx($lei, $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 } + push @{$ent->{smsg}}, _json_prep($smsg); + } + } + if ($ibx && $ibx->search) { + my $mset = $ibx->search->mset(qq{mid:"$mid"}); + for (sort { $a->get_docid <=> $b->get_docid } $mset->items) { + my $tmp = { docid => $_->get_docid }; + _inspect_doc($tmp, $_->get_document); + push @{$ent->{xdoc}}, $tmp; } } $ent; @@ -227,7 +247,7 @@ sub inspect_start ($$) { $lei->{wq1} = $self; $lei->wait_wq_events($op_c, $ops); $self->wq_do('inspect_argv'); - $self->wq_close(1); + $self->wq_close; } sub ins_add { # InputPipe->consume callback @@ -269,10 +289,15 @@ no args allowed on command-line with --stdin } sub _complete_inspect { - my ($lei, @argv) = @_; - my $lms = $lei->lms or return; - my $match_cb = $lei->complete_url_prepare(\@argv); - map { $match_cb->($_) } $lms->folders; + require PublicInbox::LeiRefreshMailSync; + PublicInbox::LeiRefreshMailSync::_complete_refresh_mail_sync(@_); + # TODO: message-ids?, blobs? could get expensive... +} + +sub ipc_atfork_child { + my ($self) = @_; + $self->{lei}->_lei_atfork_child; + $self->SUPER::ipc_atfork_child; } 1;