]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiStore.pm
lei/store: use remove_doc to save some LoC
[public-inbox.git] / lib / PublicInbox / LeiStore.pm
index 08add8f5a05496ab234f5cfad9737903de0c009a..bf41dcf530942a9bc57ef8530a8629bc94906753 100644 (file)
@@ -281,8 +281,7 @@ sub remove_docids ($;@) {
        my ($self, @docids) = @_;
        my $eidx = eidx_init($self);
        for my $docid (@docids) {
-               $eidx->idx_shard($docid)->ipc_do('xdb_remove', $docid);
-               $eidx->{oidx}->delete_by_num($docid);
+               $eidx->remove_doc($docid);
                $eidx->{oidx}->{dbh}->do(<<EOF, undef, $docid);
 DELETE FROM xref3 WHERE docid = ?
 EOF
@@ -305,7 +304,7 @@ sub remove_eml {
                        $git->cat_async($oidhex, \&_remove_if_local, $self);
                }
        }
-       $git->cat_async_wait;
+       $git->async_wait_all;
        remove_docids($self, @docids);
        \@docids;
 }
@@ -512,7 +511,7 @@ sub xchg_stderr {
        return unless -e $dir;
        my $old = delete $self->{-tmp_err};
        my $pfx = POSIX::strftime('%Y%m%d%H%M%S', gmtime(time));
-       my $err = File::Temp->new(TEMPLATE => "$pfx.$$.lei_storeXXXX",
+       my $err = File::Temp->new(TEMPLATE => "$pfx.$$.err-XXXX",
                                SUFFIX => '.err', DIR => $dir);
        open STDERR, '>>', $err->filename or die "dup2: $!";
        STDERR->autoflush(1); # shared with shard subprocesses
@@ -534,10 +533,6 @@ sub done {
        $self->{priv_eidx}->done; # V2Writable::done
        xchg_stderr($self);
        die $err if $err;
-
-       # notify clients ->done has been issued
-       defined($sock_ref) and
-               $self->{s2d_op_p}->pkt_do('sto_done_complete', $sock_ref);
 }
 
 sub ipc_atfork_child {
@@ -552,32 +547,30 @@ sub ipc_atfork_child {
        $self->SUPER::ipc_atfork_child;
 }
 
+sub recv_and_run {
+       my ($self, @args) = @_;
+       local $PublicInbox::DS::in_loop = 0; # waitpid synchronously
+       $self->SUPER::recv_and_run(@args);
+}
+
 sub write_prepare {
        my ($self, $lei) = @_;
        $lei // die 'BUG: $lei not passed';
        unless ($self->{-ipc_req}) {
-               # s2d => store-to-daemon messages
-               require PublicInbox::PktOp;
-               my ($s2d_op_c, $s2d_op_p) = PublicInbox::PktOp->pair;
                my $dir = $lei->store_path;
-               $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 = ();
-               $self->ipc_worker_spawn("lei/store $dir", $lei->oldset, {
+               $self->wq_workers_start("lei/store $dir", 1, $lei->oldset, {
                                        lei => $lei,
                                        -err_wr => $w,
-                                       to_close => [ $r, $s2d_op_c->{sock} ],
-                                       s2d_op_p => $s2d_op_p,
+                                       to_close => [ $r ],
                                });
                require PublicInbox::LeiStoreErr;
                PublicInbox::LeiStoreErr->new($r, $lei);
-               $s2d_op_c->{ops} = {
-                       sto_done_complete => [ $lei->can('sto_done_complete') ]
-               };
        }
        $lei->{sto} = $self;
 }