From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 4431A1F9F3 for ; Tue, 21 Sep 2021 07:41:59 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 01/12] lei inspect: convert to WQ worker Date: Tue, 21 Sep 2021 07:41:48 +0000 Message-Id: <20210921074159.20052-2-e@80x24.org> In-Reply-To: <20210921074159.20052-1-e@80x24.org> References: <20210921074159.20052-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Xapian and SQLite access can be slow when a DB is large and/or on high-latency storage. --- lib/PublicInbox/LeiInspect.pm | 31 +++++++++++++++++++++---------- 1 file 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 {