about summary refs log tree commit
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-08-01 08:12:26 +0000
committerEric Wong <e@yhbt.net>2020-08-02 08:26:19 +0000
commitfb4bfa102bfa702f13948ac689e54bac9d0084e0 (patch)
tree941b96a3d89df231232adf4ceec65a739ed890b4
parent84e006fdb9fb72010d6a0dac15287ff43bd1772c (diff)
downloadpublic-inbox-fb4bfa102bfa702f13948ac689e54bac9d0084e0.tar.gz
We can rely on the newer mids() sub directly and use faster
numeric comparisons for Msgmap unindexing in v1.
-rw-r--r--lib/PublicInbox/MID.pm5
-rw-r--r--lib/PublicInbox/SearchIdx.pm16
-rw-r--r--t/search.t1
3 files changed, 9 insertions, 13 deletions
diff --git a/lib/PublicInbox/MID.pm b/lib/PublicInbox/MID.pm
index 685306db..e9a3b0c0 100644
--- a/lib/PublicInbox/MID.pm
+++ b/lib/PublicInbox/MID.pm
@@ -6,7 +6,7 @@ package PublicInbox::MID;
 use strict;
 use warnings;
 use base qw/Exporter/;
-our @EXPORT_OK = qw(mid_clean id_compress mid2path mid_mime mid_escape MID_ESC
+our @EXPORT_OK = qw(mid_clean id_compress mid2path mid_escape MID_ESC
         mids references mids_for_index $MID_EXTRACT);
 use URI::Escape qw(uri_escape_utf8);
 use Digest::SHA qw/sha1_hex/;
@@ -53,9 +53,6 @@ sub mid2path {
         "$x2/$x38";
 }
 
-# Only for v1 code paths:
-sub mid_mime ($) { mids($_[0]->header_obj)->[0] }
-
 # only intended for Message-ID and X-Alt-Message-ID
 sub extract_mids {
         my @mids;
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index 080aca7c..feb00de2 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -12,7 +12,7 @@ use v5.10.1;
 use parent qw(PublicInbox::Search PublicInbox::Lock Exporter);
 use PublicInbox::Eml;
 use PublicInbox::InboxWritable;
-use PublicInbox::MID qw(mid_mime mids_for_index mids);
+use PublicInbox::MID qw(mids_for_index mids);
 use PublicInbox::MsgIter;
 use PublicInbox::IdxStack;
 use Carp qw(croak);
@@ -492,6 +492,11 @@ sub unindex_eml {
         while (my ($num, $nr) = each %tmp) {
                 warn "BUG: $num appears >1 times ($nr) for $oid\n" if $nr != 1;
         }
+        if ($nr) {
+                $self->{mm}->num_delete($_) for (keys %tmp);
+        } else { # just in case msgmap and over.sqlite3 become desynched:
+                $self->{mm}->mid_delete($mids->[0]);
+        }
         xdb_remove($self, $oid, keys %tmp) if need_xapian($self);
 }
 
@@ -512,11 +517,6 @@ sub index_mm {
         }
 }
 
-sub unindex_mm {
-        my ($self, $mime) = @_;
-        $self->{mm}->mid_delete(mid_mime($mime));
-}
-
 # returns the number of bytes to add if given a non-CRLF arg
 sub crlf_adjust ($) {
         if (index($_[0], "\r\n") < 0) {
@@ -544,9 +544,7 @@ sub index_both { # git->cat_async callback
 
 sub unindex_both { # git->cat_async callback
         my ($bref, $oid, $type, $size, $self) = @_;
-        my $eml = PublicInbox::Eml->new($bref);
-        unindex_eml($self, $oid, $eml);
-        unindex_mm($self, $eml);
+        unindex_eml($self, $oid, PublicInbox::Eml->new($bref));
 }
 
 # called by public-inbox-index
diff --git a/t/search.t b/t/search.t
index a75d944c..299f57c8 100644
--- a/t/search.t
+++ b/t/search.t
@@ -420,6 +420,7 @@ $ibx->with_umask(sub {
                 $art = $ro->{over_ro}->next_by_mid($mid, \$id, \$prev);
                 ok($art, 'article exists in OVER DB');
         }
+        $rw->_msgmap_init;
         $rw->unindex_eml($oid, $amsg);
         $rw->commit_txn_lazy;
         SKIP: {