From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-3.9 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id A4CF31F9E5 for ; Thu, 1 Apr 2021 12:10:42 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/5] lei q: reduce lei/store work for kw changes to stored mail Date: Thu, 1 Apr 2021 17:10:39 +0500 Message-Id: <20210401121042.6456-3-e@80x24.org> In-Reply-To: <20210401121042.6456-1-e@80x24.org> References: <20210401121042.6456-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 9 +++++---- lib/PublicInbox/LeiStore.pm | 8 ++++---- lib/PublicInbox/LeiToMail.pm | 6 +++--- 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 da633da4..0364d8ef 100644 --- a/lib/PublicInbox/LeiToMail.pm +++ b/lib/PublicInbox/LeiToMail.pm @@ -228,10 +228,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);