From eb48e7d6675babdda9a36be1a490c29a2ccddbdc Mon Sep 17 00:00:00 2001 From: "Eric Wong (Contractor, The Linux Foundation)" Date: Mon, 19 Mar 2018 08:14:39 +0000 Subject: v2writable: implement remove correctly We need to hide removals from anybody hitting the search engine. --- lib/PublicInbox/SearchIdx.pm | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'lib/PublicInbox/SearchIdx.pm') diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index ccec0181..ae2544da 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -440,6 +440,31 @@ sub remove_message { } } +# MID is a hint in V2 +sub remove_by_oid { + my ($self, $oid, $mid) = @_; + my $db = $self->{xdb}; + + # XXX careful, we cannot use batch_do here since we conditionally + # delete documents based on other factors, so we cannot call + # find_doc_ids twice. + my ($head, $tail) = $self->find_doc_ids('Q' . $mid); + return if $head == $tail; + + # there is only ONE element in @delete unless we + # have bugs in our v2writable deduplication check + my @delete; + for (; $head != $tail; $head->inc) { + my $docid = $head->get_docid; + my $doc = $db->get_document($docid); + my $smsg = PublicInbox::SearchMsg->wrap($doc, $mid); + $smsg->load_expand; + push(@delete, $docid) if $smsg->{blob} eq $oid; + } + $db->delete_document($_) foreach @delete; + scalar(@delete); +} + sub term_generator { # write-only my ($self) = @_; @@ -896,4 +921,11 @@ sub remote_close { $? == 0 or die ref($self)." pid:$pid exited with: $?"; } +# triggers remove_by_oid in partition or skeleton +sub remote_remove { + my ($self, $oid, $mid) = @_; + print { $self->{w} } "D $oid $mid\n" or + die "failed to write remove $!"; +} + 1; -- cgit v1.2.3-24-ge0c7