]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei q: reduce lei/store work for kw changes to stored mail
authorEric Wong <e@80x24.org>
Thu, 1 Apr 2021 12:10:39 +0000 (17:10 +0500)
committerEric Wong <e@80x24.org>
Thu, 1 Apr 2021 18:25:15 +0000 (18:25 +0000)
We can tweak lse->kw_changed to return docids and reduce IPC
traffic and reduce work the lei/store worker needs to do.

lib/PublicInbox/LeiSearch.pm
lib/PublicInbox/LeiStore.pm
lib/PublicInbox/LeiToMail.pm

index 07d570ecb7238f7120b2cb5d236b00695c1d09d5..69ba8303189fda562b9f6a83eb8df1adf1f24ab1 100644 (file)
@@ -100,10 +100,11 @@ sub xoids_for {
 
 # returns true if $eml is indexed by lei/store and keywords don't match
 sub kw_changed {
-       my ($self, $eml, $new_kw_sorted) = @_;
-       my $xoids = xoids_for($self, $eml, 1) // return;
-       my ($num) = values %$xoids;
-       my @cur_kw = msg_keywords($self, $num);
+       my ($self, $eml, $new_kw_sorted, $docids) = @_;
+       my $xoids = xoids_for($self, $eml) // return;
+       $docids //= [];
+       @$docids = sort { $a <=> $b } values %$xoids;
+       my @cur_kw = msg_keywords($self, $docids->[0]);
        join("\0", @$new_kw_sorted) eq join("\0", @cur_kw) ? 0 : 1;
 }
 
index b76af4d3f2ce861b02d324b2e4711d2a3cc543b0..48ab1d7657ef274376fde197f84458d2b9838b52 100644 (file)
@@ -131,13 +131,13 @@ sub _docids_for ($$) {
 }
 
 sub set_eml_vmd {
-       my ($self, $eml, $vmd) = @_;
+       my ($self, $eml, $vmd, $docids) = @_;
        my $eidx = eidx_init($self);
-       my @docids = _docids_for($self, $eml);
-       for my $docid (@docids) {
+       $docids //= [ _docids_for($self, $eml) ];
+       for my $docid (@$docids) {
                $eidx->idx_shard($docid)->ipc_do('set_vmd', $docid, $vmd);
        }
-       \@docids;
+       $docids;
 }
 
 sub add_eml_vmd {
index 4c33c7529a1042f0a58eb0f2540756fb2eb144da..95de5e9c1527f7951e2ad7c8c9d37bd0bbef0d35 100644 (file)
@@ -227,10 +227,10 @@ sub _mbox_write_cb ($$) {
 sub update_kw_maybe ($$$$) {
        my ($lei, $lse, $eml, $kw) = @_;
        return unless $lse;
-       my $lse_oids = $lse->kw_changed($eml, $kw);
+       my $c = $lse->kw_changed($eml, $kw, my $docids = []);
        my $vmd = { kw => $kw };
-       if ($lse_oids) { # already in lei/store
-               $lei->{sto}->ipc_do('set_eml', $eml, $vmd);
+       if (scalar @$docids) { # already in lei/store
+               $lei->{sto}->ipc_do('set_eml_vmd', undef, $vmd, $docids) if $c;
        } elsif (my $xoids = $lei->{ale}->xoids_for($eml)) {
                # it's in an external, only set kw, here
                $lei->{sto}->ipc_do('set_xvmd', $xoids, $eml, $vmd);