]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiImport.pm
lei_mail_sync: rely on flock(2), avoid IPC
[public-inbox.git] / lib / PublicInbox / LeiImport.pm
index cddd56192fad72700115579d3b1cfced28a33818..9084d771cf521cefd8b64c738f0ceec07020bca5 100644 (file)
@@ -35,13 +35,13 @@ sub pmdir_cb { # called via wq_io_do from LeiPmdir->each_mdir_fn
                die "BUG: $f was not from a Maildir?\n";
        my $kw = PublicInbox::MdirReader::flags2kw($fl);
        substr($folder, 0, 0) = 'maildir:'; # add prefix
-       my $lms = $self->{-lms_ro};
+       my $lse = $self->{lse} //= $self->{lei}->{sto}->search;
+       my $lms = $self->{-lms_ro} //= $self->{lei}->lms; # may be 0 or undef
        my $oidbin = $lms ? $lms->name_oidbin($folder, $bn) : undef;
-       my @docids = defined($oidbin) ?
-                       $self->{over}->oidbin_exists($oidbin) : ();
+       my @docids = defined($oidbin) ? $lse->over->oidbin_exists($oidbin) : ();
        my $vmd = $self->{-import_kw} ? { kw => $kw } : undef;
        if (scalar @docids) {
-               $self->{lse}->kw_changed(undef, $kw, \@docids) or return;
+               $lse->kw_changed(undef, $kw, \@docids) or return;
        }
        if (my $eml = eml_from_path($f)) {
                $vmd->{sync_info} = [ $folder, \$bn ] if $self->{-mail_sync};
@@ -78,12 +78,14 @@ sub do_import_index ($$@) {
        $j =~ /\A([0-9]+),[0-9]+\z/ and $j = $1 + 0;
        $j ||= scalar(@{$self->{inputs}}) || 1;
        my $ikw;
-       if (my $net = $lei->{net}) {
+       my $net = $lei->{net};
+       if ($net) {
                # $j = $net->net_concurrency($j); TODO
                if ($lei->{opt}->{incremental} // 1) {
                        $net->{incremental} = 1;
-                       $net->{-lms_ro} = $sto->search->lms // 0;
+                       $net->{-lms_ro} = $lei->lms // 0;
                        if ($self->{-import_kw} && $net->{-lms_ro} &&
+                                       !$lei->{opt}->{'new-only'} &&
                                        $net->{imap_order}) {
                                require PublicInbox::LeiImportKw;
                                $ikw = PublicInbox::LeiImportKw->new($lei);
@@ -94,9 +96,11 @@ sub do_import_index ($$@) {
                my $nproc = $self->detect_nproc;
                $j = $nproc if $j > $nproc;
        }
+       if ($lei->{opt}->{'new-only'} && (!$net || !$net->{imap_order})) {
+               $lei->err('# --new-only is only for IMAP');
+       }
        my $ops = {};
        $lei->{auth}->op_merge($ops, $self) if $lei->{auth};
-       $self->{-wq_nr_workers} = $j // 1; # locked
        $lei->{-eml_noisy} = 1;
        (my $op_c, $ops) = $lei->workers_start($self, $j, $ops);
        $lei->{wq1} = $self;
@@ -113,16 +117,18 @@ sub lei_import { # the main "lei import" method
 
 sub _complete_import {
        my ($lei, @argv) = @_;
-       my $sto = $lei->_lei_store or return;
-       my $lms = $sto->search->lms or return;
        my $match_cb = $lei->complete_url_prepare(\@argv);
-       map { $match_cb->($_) } $lms->folders;
+       my @m = map { $match_cb->($_) } $lei->url_folder_cache->keys;
+       my %f = map { $_ => 1 } @m;
+       if (my $lms = $lei->lms) {
+               @m = map { $match_cb->($_) } $lms->folders;
+               @f{@m} = @m;
+       }
+       keys %f;
 }
 
 no warnings 'once';
 *ipc_atfork_child = \&PublicInbox::LeiInput::input_only_atfork_child;
 *net_merge_all_done = \&PublicInbox::LeiInput::input_only_net_merge_all_done;
 
-# the following works even when LeiAuth is lazy-loaded
-*net_merge_all = \&PublicInbox::LeiAuth::net_merge_all;
 1;