]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/V2Writable.pm
v2writable: cleanup unused pipes in partitions
[public-inbox.git] / lib / PublicInbox / V2Writable.pm
index cf19c7610cb775f1cb09d5c985442046996ce52a..3451261e4ee1f902dddce340a4a38780cfae3795 100644 (file)
@@ -63,7 +63,7 @@ sub add {
        my ($len, $msgref) = @{$im->{last_object}};
 
        $self->idx_init;
-       my $num = $self->{all}->index_mm($mime);
+       my $num = $self->{all}->index_mm($mime, 1);
        my $nparts = $self->{partitions};
        my $part = $num % $nparts;
        my $idx = $self->idx_part($part);
@@ -84,9 +84,9 @@ sub idx_part {
 sub idx_init {
        my ($self) = @_;
        return if $self->{idx_parts};
-       # first time initialization:
-       my $all = $self->{all} =
-               PublicInbox::SearchIdxThread->new($self->{-inbox});
+
+       # first time initialization, first we create the threader pipe:
+       my $all = $self->{all} = PublicInbox::SearchIdxThread->new($self);
 
        # need to create all parts before initializing msgmap FD
        my $max = $self->{partitions} - 1;
@@ -94,6 +94,8 @@ sub idx_init {
        for my $i (0..$max) {
                push @$idx, PublicInbox::SearchIdxPart->new($self, $i, $all);
        }
+
+       # Now that all subprocesses are up, we can open the FD for SQLite:
        $all->_msgmap_init->{dbh}->begin_work;
 }
 
@@ -242,4 +244,14 @@ sub lookup_content {
        undef # TODO
 }
 
+sub atfork_child {
+       my ($self) = @_;
+       if (my $parts = $self->{idx_parts}) {
+               $_->atfork_child foreach @$parts;
+       }
+       if (my $im = $self->{im}) {
+               $im->atfork_child;
+       }
+}
+
 1;