]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiQuery.pm
lei q: import flags when clobbering/augmenting Maildirs
[public-inbox.git] / lib / PublicInbox / LeiQuery.pm
index 64c9394c6186def834c976371b759c29b367245d..c630d62809a38fa1184cdcb71b7f8cd0e4d87b80 100644 (file)
@@ -5,6 +5,7 @@
 package PublicInbox::LeiQuery;
 use strict;
 use v5.10.1;
+use POSIX ();
 
 sub prep_ext { # externals_each callback
        my ($lxs, $exclude, $loc) = @_;
@@ -13,9 +14,9 @@ sub prep_ext { # externals_each callback
 
 sub _start_query {
        my ($self) = @_;
-       if (my $net = $self->{net}) {
+       if ($self->{net}) {
                require PublicInbox::LeiAuth;
-               $self->{auth} = PublicInbox::LeiAuth->new($net);
+               $self->{auth} = PublicInbox::LeiAuth->new
        }
        $self->{lxs}->do_query($self);
 }
@@ -50,6 +51,10 @@ sub lei_q {
        # we'll allow "--only $LOCATION --local"
        my $sto = $self->_lei_store(1);
        my $lse = $sto->search;
+       if (($opt->{'import-remote'} //= 1) |
+                       ($opt->{'import-augment'} //= 1)) {
+               $sto->write_prepare($self);
+       }
        if ($opt->{'local'} //= scalar(@only) ? 0 : 1) {
                $lxs->prepare_external($lse);
        }
@@ -94,7 +99,10 @@ sub lei_q {
                return $self->fail("`$mj' writer jobs must be >= 1");
        }
        PublicInbox::LeiOverview->new($self) or return;
-       $self->{l2m}->{-wq_nr_workers} = ($mj // $nproc) if $self->{l2m};
+       $self->{l2m} and $self->{l2m}->{-wq_nr_workers} = $mj // do {
+               $mj = POSIX::lround($nproc * 3 / 4); # keep some CPU for git
+               $mj <= 0 ? 1 : $mj;
+       };
 
        my %mset_opt = map { $_ => $opt->{$_} } qw(threads limit offset);
        $mset_opt{asc} = $opt->{'reverse'} ? 1 : 0;