]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiStore.pm
lei index: new command to index mail w/o git storage
[public-inbox.git] / lib / PublicInbox / LeiStore.pm
index f8371abfcb69b347abd6fd525abcf92bfdc30d78..a7a0ebef097d41f68f1adfe0b0de4b656d1b702b 100644 (file)
@@ -88,6 +88,7 @@ sub importer {
                $self->checkpoint;
                $max = $self->git_epoch_max + 1;
        }
+       my (undef, $tl) = eidx_init($self); # acquire lock
        my $pfx = $self->git_pfx;
        $max //= $self->git_epoch_max;
        while (1) {
@@ -97,7 +98,9 @@ sub importer {
                my $git = PublicInbox::Git->new($latest);
                if (!$old) {
                        $git->qx(qw(config core.sharedRepository 0600));
-                       $self->done; # force eidx_init on next round
+                       $self->done; # unlock
+                       # re-acquire lock, update alternates for new epoch
+                       (undef, $tl) = eidx_init($self);
                }
                my $packed_bytes = $git->packed_bytes;
                my $unpacked_bytes = $packed_bytes / $self->packing_factor;
@@ -130,7 +133,7 @@ sub eidx_init {
        my $tl = wantarray && $self->{-err_wr} ?
                        PublicInbox::OnDestroy->new($$, \&_tail_err, $self) :
                        undef;
-       $eidx->idx_init({-private => 1});
+       $eidx->idx_init({-private => 1}); # acquires lock
        wantarray ? ($eidx, $tl) : $eidx;
 }
 
@@ -190,13 +193,29 @@ sub remove_eml_vmd {
        \@docids;
 }
 
+sub set_sync_info {
+       my ($self, $oidhex, $folder, $id) = @_;
+       ($self->{lms} //= do {
+               require PublicInbox::LeiMailSync;
+               my $f = "$self->{priv_eidx}->{topdir}/mail_sync.sqlite3";
+               my $lms = PublicInbox::LeiMailSync->new($f);
+               $lms->lms_begin;
+               $lms;
+       })->set_src($oidhex, $folder, $id);
+}
+
 sub add_eml {
        my ($self, $eml, $vmd, $xoids) = @_;
-       my $im = $self->importer; # may create new epoch
-       my ($eidx, $tl) = eidx_init($self); # updates/writes alternates file
+       my $im = $self->{-fake_im} // $self->importer; # may create new epoch
+       my ($eidx, $tl) = eidx_init($self);
        my $oidx = $eidx->{oidx}; # PublicInbox::Import::add checks this
        my $smsg = bless { -oidx => $oidx }, 'PublicInbox::Smsg';
-       $im->add($eml, undef, $smsg) or return; # duplicate returns undef
+       $smsg->{-eidx_git} = $eidx->git if !$self->{-fake_im};
+       my $im_mark = $im->add($eml, undef, $smsg);
+       if ($vmd && $vmd->{sync_info}) {
+               set_sync_info($self, $smsg->{blob}, @{$vmd->{sync_info}});
+       }
+       $im_mark or return; # duplicate blob returns undef
 
        local $self->{current_info} = $smsg->{blob};
        my $vivify_xvmd = delete($smsg->{-vivify_xvmd}) // []; # exact matches
@@ -258,6 +277,13 @@ sub set_eml {
                set_eml_vmd($self, $eml, $vmd);
 }
 
+sub index_eml_only {
+       my ($self, $eml, $vmd, $xoids) = @_;
+       require PublicInbox::FakeImport;
+       local $self->{-fake_im} = PublicInbox::FakeImport->new;
+       set_eml($self, $eml, $vmd, $xoids);
+}
+
 sub _external_only ($$$) {
        my ($self, $xoids, $eml) = @_;
        my $eidx = $self->{priv_eidx};
@@ -379,6 +405,9 @@ sub done {
                        warn $err;
                }
        }
+       if (my $lms = delete $self->{lms}) {
+               $lms->lms_commit;
+       }
        $self->{priv_eidx}->done; # V2Writable::done
        xchg_stderr($self);
        die $err if $err;
@@ -393,7 +422,6 @@ sub ipc_atfork_child {
                close $err->[0];
                $self->{-err_wr} = $err->[1];
        }
-       $SIG{__WARN__} = PublicInbox::Eml::warn_ignore_cb();
        $self->SUPER::ipc_atfork_child;
 }