about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-09-21 07:41:48 +0000
committerEric Wong <e@80x24.org>2021-09-21 19:18:34 +0000
commiteed4017d3361220e7533d786565c3633e305cc16 (patch)
tree9b5367b30432afdc70ccc857cba00046787bdfec /lib
parentc9c1aabe239378e50043e2a3d2e11c4e166cdda0 (diff)
downloadpublic-inbox-eed4017d3361220e7533d786565c3633e305cc16.tar.gz
Xapian and SQLite access can be slow when a DB is large and/or
on high-latency storage.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/LeiInspect.pm31
1 files changed, 21 insertions, 10 deletions
diff --git a/lib/PublicInbox/LeiInspect.pm b/lib/PublicInbox/LeiInspect.pm
index f06cea61..48da826b 100644
--- a/lib/PublicInbox/LeiInspect.pm
+++ b/lib/PublicInbox/LeiInspect.pm
@@ -8,6 +8,7 @@
 package PublicInbox::LeiInspect;
 use strict;
 use v5.10.1;
+use parent qw(PublicInbox::IPC);
 use PublicInbox::Config;
 use PublicInbox::MID qw(mids);
 
@@ -184,9 +185,11 @@ sub inspect1 ($$$) {
         1;
 }
 
-sub _inspect_argv ($$) {
-        my ($lei, $argv) = @_;
+sub inspect_argv { # via wq_do
+        my ($self) = @_;
+        my ($lei, $argv) = delete @$self{qw(lei argv)};
         my $multi = scalar(@$argv) > 1;
+        $lei->{1}->autoflush(0);
         $lei->out('[') if $multi;
         while (defined(my $x = shift @$argv)) {
                 inspect1($lei, $x, scalar(@$argv)) or return;
@@ -194,6 +197,16 @@ sub _inspect_argv ($$) {
         $lei->out(']') if $multi;
 }
 
+sub inspect_start ($$) {
+        my ($lei, $argv) = @_;
+        my $self = bless { lei => $lei, argv => $argv }, __PACKAGE__;
+        my ($op_c, $ops) = $lei->workers_start($self, 1);
+        $lei->{wq1} = $self;
+        $lei->wait_wq_events($op_c, $ops);
+        $self->wq_do('inspect_argv');
+        $self->wq_close(1);
+}
+
 sub ins_add { # InputPipe->consume callback
         my ($lei) = @_; # $_[1] = $rbuf
         if (defined $_[1]) {
@@ -201,7 +214,7 @@ sub ins_add { # InputPipe->consume callback
                         my $str = delete $lei->{istr};
                         $str =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s;
                         my $eml = PublicInbox::Eml->new(\$str);
-                        _inspect_argv($lei, [
+                        inspect_start($lei, [
                                 'blob:'.$lei->git_oid($eml)->hexdigest,
                                 map { "mid:$_" } @{mids($eml)} ]);
                 };
@@ -218,20 +231,18 @@ sub lei_inspect {
                 my $sto = $lei->_lei_store;
                 $sto ? $sto->search : undef;
         } : undef;
-        if ($lei->{opt}->{pretty} || -t $lei->{1}) {
-                $lei->{json}->pretty(1)->indent(2);
-        }
-        $lei->start_pager if -t $lei->{1};
-        $lei->{1}->autoflush(0);
+        my $isatty = -t $lei->{1};
+        $lei->{json}->pretty(1)->indent(2) if $lei->{opt}->{pretty} || $isatty;
+        $lei->start_pager if $isatty;
         if ($lei->{opt}->{stdin}) {
                 return $lei->fail(<<'') if @argv;
 no args allowed on command-line with --stdin
 
                 require PublicInbox::InputPipe;
                 PublicInbox::InputPipe::consume($lei->{0}, \&ins_add, $lei);
-                return;
+        } else {
+                inspect_start($lei, \@argv);
         }
-        _inspect_argv($lei, \@argv);
 }
 
 sub _complete_inspect {