]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchIdx.pm
searchidx: remove v1-only msg_mime sub
[public-inbox.git] / lib / PublicInbox / SearchIdx.pm
index aa8d8ce325cf203d1ea77abc9e89d7bb5b73091b..feb00de22e062a86c7042b2f5234496a9b606c61 100644 (file)
@@ -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);
@@ -21,7 +21,7 @@ use PublicInbox::OverIdx;
 use PublicInbox::Spawn qw(spawn);
 use PublicInbox::Git qw(git_unquote);
 use PublicInbox::MsgTime qw(msg_timestamp msg_datestamp);
-our @EXPORT_OK = qw(crlf_adjust log2stack is_ancestor check_size);
+our @EXPORT_OK = qw(crlf_adjust log2stack is_ancestor check_size nodatacow_dir);
 my $X = \%PublicInbox::Search::X;
 my ($DB_CREATE_OR_OPEN, $DB_OPEN);
 our $DB_NO_SYNC = 0;
@@ -110,6 +110,12 @@ sub load_xapian_writable () {
        1;
 }
 
+sub nodatacow_dir ($) {
+       my ($dir) = @_;
+       opendir my $dh, $dir or die "opendir($dir): $!\n";
+       PublicInbox::Spawn::set_nodatacow(fileno($dh));
+}
+
 sub idx_acquire {
        my ($self) = @_;
        my $flag;
@@ -128,8 +134,7 @@ sub idx_acquire {
                if (!-d $dir && (!$is_shard ||
                                ($is_shard && need_xapian($self)))) {
                        File::Path::mkpath($dir);
-                       opendir my $dh, $dir or die "opendir($dir): $!\n";
-                       PublicInbox::Spawn::set_nodatacow(fileno($dh));
+                       nodatacow_dir($dir);
                }
        }
        return unless defined $flag;
@@ -487,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);
 }
 
@@ -507,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) {
@@ -539,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