about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-04-01 17:10:39 +0500
committerEric Wong <e@80x24.org>2021-04-01 18:25:15 +0000
commit1730d031a00654a64d1854480d0e83b62c2bfecd (patch)
tree3df4298d91b53505dab9d0680c3f41b495e697fb
parent130c18936644acb3d612cc06da2772b0c13b2d72 (diff)
downloadpublic-inbox-1730d031a00654a64d1854480d0e83b62c2bfecd.tar.gz
We can tweak lse->kw_changed to return docids and reduce IPC
traffic and reduce work the lei/store worker needs to do.
-rw-r--r--lib/PublicInbox/LeiSearch.pm9
-rw-r--r--lib/PublicInbox/LeiStore.pm8
-rw-r--r--lib/PublicInbox/LeiToMail.pm6
3 files changed, 12 insertions, 11 deletions
diff --git a/lib/PublicInbox/LeiSearch.pm b/lib/PublicInbox/LeiSearch.pm
index 07d570ec..69ba8303 100644
--- a/lib/PublicInbox/LeiSearch.pm
+++ b/lib/PublicInbox/LeiSearch.pm
@@ -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;
 }
 
diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm
index b76af4d3..48ab1d76 100644
--- a/lib/PublicInbox/LeiStore.pm
+++ b/lib/PublicInbox/LeiStore.pm
@@ -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 {
diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm
index 4c33c752..95de5e9c 100644
--- a/lib/PublicInbox/LeiToMail.pm
+++ b/lib/PublicInbox/LeiToMail.pm
@@ -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);