]> Sergey Matveev's repositories - public-inbox.git/commitdiff
searchidxshard: use add_xapian directly for v2
authorEric Wong <e@80x24.org>
Sun, 3 Jan 2021 02:06:17 +0000 (02:06 +0000)
committerEric Wong <e@80x24.org>
Sun, 3 Jan 2021 18:30:33 +0000 (18:30 +0000)
We can more clearly distinguish between v1 and v2-only code
paths this way, and may be able to save a few cycles this way.

lib/PublicInbox/SearchIdx.pm
lib/PublicInbox/SearchIdxShard.pm
lib/PublicInbox/V2Writable.pm

index a7005051d9deef241fab065dd05072348e80d8ce..adced0762b41487d5bdaa69517db157901bf3076 100644 (file)
@@ -397,6 +397,7 @@ sub eml2doc ($$$;$) {
 
 sub add_xapian ($$$$) {
        my ($self, $eml, $smsg, $mids) = @_;
+       begin_txn_lazy($self);
        my $doc = eml2doc($self, $eml, $smsg, $mids);
        $self->{xdb}->replace_document($smsg->{num}, $doc);
 }
index 0051df9305286f39ea5329bfb4f64bb4bbde83d8..1598faebdc9b53b621ef369b9a249198723ca705 100644 (file)
@@ -54,7 +54,7 @@ sub ipc_atfork_child { # called automatically before ipc_worker_loop
 sub index_eml {
        my ($self, $eml, $smsg, $eidx_key) = @_;
        $smsg->{eidx_key} = $eidx_key if defined $eidx_key;
-       $self->ipc_do('add_message', $eml, $smsg);
+       $self->ipc_do('add_xapian', $eml, $smsg);
 }
 
 # wait for return to determine when ipc_do('commit_txn_lazy') is done
index 6be95979389b815a6486fc70456b5bfda0480cf7..459c7e86eed189782c5b2c4517af5587fb7d8ee4 100644 (file)
@@ -141,8 +141,10 @@ sub idx_shard ($$) {
 sub do_idx ($$$) {
        my ($self, $eml, $smsg) = @_;
        $self->{oidx}->add_overview($eml, $smsg);
-       my $idx = idx_shard($self, $smsg->{num});
-       $idx->index_eml($eml, $smsg);
+       if ($self->{-need_xapian}) {
+               my $idx = idx_shard($self, $smsg->{num});
+               $idx->index_eml($eml, $smsg);
+       }
        my $n = $self->{transact_bytes} += $smsg->{bytes};
        $n >= $self->{batch_bytes};
 }
@@ -267,6 +269,7 @@ sub _idx_init { # with_umask callback
        my $max = $self->{shards} - 1;
        my $idx = $self->{idx_shards} = [];
        push @$idx, PublicInbox::SearchIdxShard->new($self, $_) for (0..$max);
+       $self->{-need_xapian} = $idx->[0]->need_xapian;
 
        # SearchIdxShard may do their own flushing, so don't scale
        # until after forking
@@ -1129,6 +1132,7 @@ sub sync_prepare ($$) {
 sub unindex_oid_aux ($$$) {
        my ($self, $oid, $mid) = @_;
        my @removed = $self->{oidx}->remove_oid($oid, $mid);
+       return unless $self->{-need_xapian};
        for my $num (@removed) {
                idx_shard($self, $num)->ipc_do('xdb_remove', $num);
        }