user/dev discussion of public-inbox itself
 help / color / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH 3/4] searchidx: remove v1-only msg_mime sub
Date: Sat,  1 Aug 2020 08:12:26 +0000
Message-ID: <20200801081227.21412-4-e@yhbt.net> (raw)
In-Reply-To: <20200801081227.21412-1-e@yhbt.net>

We can rely on the newer mids() sub directly and use faster
numeric comparisons for Msgmap unindexing in v1.
---
 lib/PublicInbox/MID.pm       |  5 +----
 lib/PublicInbox/SearchIdx.pm | 16 +++++++---------
 t/search.t                   |  1 +
 3 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/lib/PublicInbox/MID.pm b/lib/PublicInbox/MID.pm
index 685306dbf..e9a3b0c09 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 080aca7cb..feb00de22 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 a75d944c3..299f57c85 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: {

  parent reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-01  8:12 [PATCH 0/4] cleanup some minor annoyances Eric Wong
2020-08-01  8:12 ` [PATCH 1/4] inboxwritable: mime_from_path: reduce `$/' scope and returns Eric Wong
2020-08-01  8:12 ` [PATCH 2/4] inboxwritable: rename mime_from_path to eml_from_path Eric Wong
2020-08-01  8:12 ` Eric Wong [this message]
2020-08-01  8:12 ` [PATCH 4/4] remove unnecessary ->header_obj calls Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200801081227.21412-4-e@yhbt.net \
    --to=e@yhbt.net \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror http://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git