]> 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 69d2f9a604dd02a9fcd4014fe4a8936b3af99f10..941bc2997737a294f88a52d8a3942fdc9bb1da51 100644 (file)
@@ -23,16 +23,15 @@ 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};
-
-       # --local is enabled by default
-       # src: LeiXSearch || LeiSearch || Inbox
-       my @srcs;
        require PublicInbox::LeiXSearch;
        require PublicInbox::LeiOverview;
-       require PublicInbox::LeiDedupe;
+       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
@@ -41,15 +40,18 @@ sub lei_q {
        }
        my $j = $opt->{jobs} // (scalar(@srcs) > 3 ? 3 : scalar(@srcs));
        $j = 1 if !$opt->{thread};
-       $j++ if $opt->{'local'}; # for sto->search below
        $self->atfork_prepare_wq($lxs);
-       $lxs->wq_workers_start('lei_xsearch', $j, $self->oldset)
-               // $lxs->wq_workers($j);
+       $lxs->wq_workers_start('lei_xsearch', $j, $self->oldset);
+       $self->{lxs} = $lxs;
 
-       unshift(@srcs, $sto->search) if $opt->{'local'};
+       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);
+       }
        # no forking workers after this
-       $self->{ovv} = PublicInbox::LeiOverview->new($self);
-       $self->{dd} = PublicInbox::LeiDedupe->new($self);
+
        my %mset_opt = map { $_ => $opt->{$_} } qw(thread limit offset);
        $mset_opt{asc} = $opt->{'reverse'} ? 1 : 0;
        $mset_opt{qstr} = join(' ', map {;
@@ -69,12 +71,10 @@ 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);
+       $ovv->ovv_begin($self);
        $lxs->do_query($self, \@srcs);
 }