From 5be0cb101bab44167a78af7a2d167f254c95bdb3 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 23 Mar 2021 11:02:17 +0600 Subject: lei mark: command for (un)setting keywords and labels Only tested for keywords and labels with file inputs, so far; but it seems to do what it needs to do. There's a bit more redundant code than I'd like, and more opportunities for code sharing in the future "lei import" will be expanded to support +kw:$KEYWORD and +L:$LABEL in the future. --- lib/PublicInbox/LeiStore.pm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lib/PublicInbox/LeiStore.pm') diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm index b390b318..b5d43b7e 100644 --- a/lib/PublicInbox/LeiStore.pm +++ b/lib/PublicInbox/LeiStore.pm @@ -228,12 +228,30 @@ sub set_eml { set_eml_vmd($self, $eml, $vmd); } +sub update_xvmd { + my ($self, $xoids, $vmd_mod) = @_; + my $eidx = eidx_init($self); + my $oidx = $eidx->{oidx}; + my %seen; + for my $oid (keys %$xoids) { + my @docids = $oidx->blob_exists($oid) or next; + scalar(@docids) > 1 and + warn "W: $oid indexed as multiple docids: @docids\n"; + for my $docid (@docids) { + next if $seen{$docid}++; + my $idx = $eidx->idx_shard($docid); + $idx->ipc_do('update_vmd', $docid, $vmd_mod); + } + } +} + # set or update keywords for external message, called via ipc_do sub set_xvmd { my ($self, $xoids, $eml, $vmd) = @_; my $eidx = eidx_init($self); my $oidx = $eidx->{oidx}; + my %seen; # see if we can just update existing docs for my $oid (keys %$xoids) { @@ -241,6 +259,7 @@ sub set_xvmd { scalar(@docids) > 1 and warn "W: $oid indexed as multiple docids: @docids\n"; for my $docid (@docids) { + next if $seen{$docid}++; my $idx = $eidx->idx_shard($docid); $idx->ipc_do('set_vmd', $docid, $vmd); } -- cgit v1.2.3-24-ge0c7