]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiQuery.pm
lei q: cleanup store initialization
[public-inbox.git] / lib / PublicInbox / LeiQuery.pm
index 7ca01454f04c7d65bc421582d1143758032ef350..941bc2997737a294f88a52d8a3942fdc9bb1da51 100644 (file)
@@ -23,35 +23,35 @@ sub _vivify_external { # _externals_each callback
 # the main "lei q SEARCH_TERMS" method
 sub lei_q {
        my ($self, @argv) = @_;
-       my $sto = $self->_lei_store(1);
-       my $cfg = $self->_lei_cfg(1);
-       my $opt = $self->{opt};
-       require PublicInbox::LeiDedupe;
-       my $dd = PublicInbox::LeiDedupe->new($self);
-
-       # --local is enabled by default
-       # src: LeiXSearch || LeiSearch || Inbox
-       my @srcs;
        require PublicInbox::LeiXSearch;
        require PublicInbox::LeiOverview;
+       PublicInbox::Config->json; # preload before forking
+       my $opt = $self->{opt};
+       my @srcs; # any number of LeiXSearch || LeiSearch || Inbox
+       if ($opt->{'local'} //= 1) { # --local is enabled by default
+               my $sto = $self->_lei_store(1);
+               push @srcs, $sto->search;
+       }
        my $lxs = PublicInbox::LeiXSearch->new;
 
        # --external is enabled by default, but allow --no-external
        if ($opt->{external} // 1) {
                $self->_externals_each(\&_vivify_external, \@srcs);
        }
-       my $j = $opt->{jobs} // scalar(@srcs) > 3 ? 3 : scalar(@srcs);
+       my $j = $opt->{jobs} // (scalar(@srcs) > 3 ? 3 : scalar(@srcs));
        $j = 1 if !$opt->{thread};
-       $j++ if $opt->{'local'}; # for sto->search below
-       if ($self->{sock}) {
-               $self->atfork_prepare_wq($lxs);
-               $lxs->wq_workers_start('lei_xsearch', $j, $self->oldset)
-                       // $lxs->wq_workers($j);
+       $self->atfork_prepare_wq($lxs);
+       $lxs->wq_workers_start('lei_xsearch', $j, $self->oldset);
+       $self->{lxs} = $lxs;
+
+       my $ovv = PublicInbox::LeiOverview->new($self) or return;
+       if (my $l2m = $self->{l2m}) {
+               $j = 4 if $j <= 4; # TODO configurable
+               $self->atfork_prepare_wq($l2m);
+               $l2m->wq_workers_start('lei2mail', $j, $self->oldset);
        }
-       unshift(@srcs, $sto->search) if $opt->{'local'};
        # no forking workers after this
-       require PublicInbox::LeiOverview;
-       $self->{ovv} = PublicInbox::LeiOverview->new($self);
+
        my %mset_opt = map { $_ => $opt->{$_} } qw(thread limit offset);
        $mset_opt{asc} = $opt->{'reverse'} ? 1 : 0;
        $mset_opt{qstr} = join(' ', map {;
@@ -71,22 +71,11 @@ sub lei_q {
                        die "unrecognized --sort=$sort\n";
                }
        }
-       # $self->out($json->encode(\%mset_opt));
        # descending docid order
        $mset_opt{relevance} //= -2 if $opt->{thread};
-       # my $wcb = PublicInbox::LeiToMail->write_cb($out, $self);
        $self->{mset_opt} = \%mset_opt;
-       $self->{ovv}->ovv_begin($self);
-       pipe(my ($eof_wait, $qry_done)) or die "pipe $!";
-       require PublicInbox::EOFpipe;
-       my $eof = PublicInbox::EOFpipe->new($eof_wait, \&query_done, $self);
-       $lxs->do_query($self, $qry_done, \@srcs);
-       $eof->event_step unless $self->{sock};
-}
-
-sub query_done { # PublicInbox::EOFpipe callback
-       my ($self) = @_;
-       $self->{ovv}->ovv_end($self);
+       $ovv->ovv_begin($self);
+       $lxs->do_query($self, \@srcs);
 }
 
 1;