]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchIdx.pm
remove unnecessary ->header_obj calls
[public-inbox.git] / lib / PublicInbox / SearchIdx.pm
index 080aca7cb7b79cb05509ef2a1916d0f65430ff5b..a1baa65bd2945dcc8885fc70735a1d60ecd5853b 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);
@@ -350,8 +350,7 @@ sub index_ids ($$$$) {
 }
 
 sub add_xapian ($$$$) {
-       my ($self, $mime, $smsg, $mids) = @_;
-       my $hdr = $mime->header_obj;
+       my ($self, $eml, $smsg, $mids) = @_;
        my $doc = $X->{Document}->new;
        add_val($doc, PublicInbox::Search::TS(), $smsg->{ts});
        my @ds = gmtime($smsg->{ds});
@@ -366,10 +365,10 @@ sub add_xapian ($$$$) {
        $tg->set_document($doc);
        index_headers($self, $smsg);
 
-       msg_iter($mime, \&index_xapian, [ $self, $doc ]);
-       index_ids($self, $doc, $hdr, $mids);
+       msg_iter($eml, \&index_xapian, [ $self, $doc ]);
+       index_ids($self, $doc, $eml, $mids);
        $smsg->{to} = $smsg->{cc} = ''; # WWW doesn't need these, only NNTP
-       PublicInbox::OverIdx::parse_references($smsg, $hdr, $mids);
+       PublicInbox::OverIdx::parse_references($smsg, $eml, $mids);
        my $data = $smsg->to_doc_data;
        $doc->set_data($data);
        if (my $altid = $self->{-altid}) {
@@ -398,8 +397,7 @@ sub _msgmap_init ($) {
 sub add_message {
        # mime = PublicInbox::Eml or Email::MIME object
        my ($self, $mime, $smsg, $sync) = @_;
-       my $hdr = $mime->header_obj;
-       my $mids = mids_for_index($hdr);
+       my $mids = mids_for_index($mime);
        $smsg //= bless { blob => '' }, 'PublicInbox::Smsg'; # test-only compat
        $smsg->{mid} //= $mids->[0]; # v1 compatibility
        $smsg->{num} //= do { # v1
@@ -408,7 +406,7 @@ sub add_message {
        };
 
        # v1 and tests only:
-       $smsg->populate($hdr, $sync);
+       $smsg->populate($mime, $sync);
        $smsg->{bytes} //= length($mime->as_string);
 
        eval {
@@ -492,6 +490,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 +515,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 +542,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