]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiStore.pm
lei_input: set and prepare watches early
[public-inbox.git] / lib / PublicInbox / LeiStore.pm
index 28e36e89c7ca04c75da16e68ef34080bb3c8780e..0fa2d3c08ba901e12f0900786f6bd9a3fab18e9d 100644 (file)
@@ -28,6 +28,7 @@ use PublicInbox::Spawn qw(spawn);
 use List::Util qw(max);
 use File::Temp ();
 use POSIX ();
+use IO::Handle (); # ->autoflush
 
 sub new {
        my (undef, $dir, $opt) = @_;
@@ -201,7 +202,7 @@ sub _lms_rw ($) {
                require PublicInbox::LeiMailSync;
                my $f = "$self->{priv_eidx}->{topdir}/mail_sync.sqlite3";
                my $lms = PublicInbox::LeiMailSync->new($f);
-               $lms->lms_begin;
+               $lms->lms_write_prepare;
                $lms;
        };
 }
@@ -229,7 +230,7 @@ sub lms_rename_folder {
 
 sub set_sync_info {
        my ($self, $oidhex, $folder, $id) = @_;
-       _lms_rw($self)->set_src($oidhex, $folder, $id);
+       _lms_rw($self)->set_src(pack('H*', $oidhex), $folder, $id);
 }
 
 sub _remove_if_local { # git->cat_async arg
@@ -242,8 +243,8 @@ sub remove_docids ($;@) {
        my $eidx = eidx_init($self);
        for my $docid (@docids) {
                $eidx->idx_shard($docid)->ipc_do('xdb_remove', $docid);
-               $self->{oidx}->delete_by_num($docid);
-               $self->{oidx}->{dbh}->do(<<EOF, undef, $docid);
+               $eidx->{oidx}->delete_by_num($docid);
+               $eidx->{oidx}->{dbh}->do(<<EOF, undef, $docid);
 DELETE FROM xref3 WHERE docid = ?
 EOF
        }
@@ -449,9 +450,7 @@ sub checkpoint {
        if (my $im = $self->{im}) {
                $wait ? $im->barrier : $im->checkpoint;
        }
-       if (my $lms = delete $self->{lms}) {
-               $lms->lms_commit;
-       }
+       delete $self->{lms};
        $self->{priv_eidx}->checkpoint($wait);
 }
 
@@ -480,9 +479,7 @@ sub done {
                        warn $err;
                }
        }
-       if (my $lms = delete $self->{lms}) {
-               $lms->lms_commit;
-       }
+       delete $self->{lms};
        $self->{priv_eidx}->done; # V2Writable::done
        xchg_stderr($self);
        die $err if $err;
@@ -514,6 +511,7 @@ sub write_prepare {
                $self->ipc_lock_init("$dir/ipc.lock");
                substr($dir, -length('/lei/store'), 10, '');
                pipe(my ($r, $w)) or die "pipe: $!";
+               $w->autoflush(1);
                # Mail we import into lei are private, so headers filtered out
                # by -mda for public mail are not appropriate
                local @PublicInbox::MDA::BAD_HEADERS = ();
@@ -539,4 +537,11 @@ sub git_blob_id { # called via LEI->git_blob_id
        git_sha(1, $eml)->hexdigest;
 }
 
+# called by lei-daemon before lei->refresh_watches
+sub add_sync_folders {
+       my ($self, @folders) = @_;
+       my $lms = _lms_rw($self);
+       for my $f (@folders) { $lms->fid_for($f, 1) }
+}
+
 1;