user/dev discussion of public-inbox itself
 help / color / mirror / Atom feed
* [PATCH] searchidx: fix (undocumented) --skip-docdata handling
@ 2020-09-24 10:13 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2020-09-24 10:13 UTC (permalink / raw)
  To: meta

This switch is still undocumented, but we can reduce the scope
of our Xapian docdata dependency by moving its only caller to
SearchIdx.  This reduces the amount of code loaded by read-only
code paths.
---
 lib/PublicInbox/Search.pm    |  3 ---
 lib/PublicInbox/SearchIdx.pm | 26 ++++++++++++++++++++++----
 lib/PublicInbox/Smsg.pm      | 18 ------------------
 t/search.t                   |  4 ++--
 4 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index fb35b747..0321ca93 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -90,9 +90,6 @@ sub load_xapian () {
 		$ENQ_ASCENDING = $x eq 'Xapian' ?
 				1 : Search::Xapian::ENQ_ASCENDING();
 
-		# for Smsg:
-		*PublicInbox::Smsg::sortable_unserialise =
-						$Xap.'::sortable_unserialise';
 		# n.b. FLAG_PURE_NOT is expensive not suitable for a public
 		# website as it could become a denial-of-service vector
 		# FLAG_PHRASE also seems to cause performance problems chert
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index eb620f44..803494f5 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -17,6 +17,7 @@ use PublicInbox::MsgIter;
 use PublicInbox::IdxStack;
 use Carp qw(croak);
 use POSIX qw(strftime);
+use Time::Local qw(timegm);
 use PublicInbox::OverIdx;
 use PublicInbox::Spawn qw(spawn nodatacow_dir);
 use PublicInbox::Git qw(git_unquote);
@@ -104,6 +105,7 @@ sub load_xapian_writable () {
 	}
 	eval 'require '.$X->{WritableDatabase} or die;
 	*sortable_serialise = $xap.'::sortable_serialise';
+	*sortable_unserialise = $xap.'::sortable_unserialise';
 	$DB_CREATE_OR_OPEN = eval($xap.'::DB_CREATE_OR_OPEN()');
 	$DB_OPEN = eval($xap.'::DB_OPEN()');
 	my $ver = (eval($xap.'::major_version()') << 16) |
@@ -434,6 +436,23 @@ sub add_message {
 	$smsg->{num};
 }
 
+sub get_val ($$) {
+	my ($doc, $col) = @_;
+	sortable_unserialise($doc->get_value($col));
+}
+
+sub smsg_from_doc ($) {
+	my ($doc) = @_;
+	my $data = $doc->get_data or return;
+	my $smsg = bless {}, 'PublicInbox::Smsg';
+	$smsg->{ts} = get_val($doc, PublicInbox::Search::TS());
+	my $dt = get_val($doc, PublicInbox::Search::DT());
+	my ($yyyy, $mon, $dd, $hh, $mm, $ss) = unpack('A4A2A2A2A2A2', $dt);
+	$smsg->{ds} = timegm($ss, $mm, $hh, $dd, $mon - 1, $yyyy);
+	$smsg->load_from_data($data);
+	$smsg;
+}
+
 sub xdb_remove {
 	my ($self, $oid, @removed) = @_;
 	my $xdb = $self->{xdb} or return;
@@ -444,10 +463,9 @@ sub xdb_remove {
 			warn "E: #$num $oid missing in Xapian\n";
 			next;
 		}
-		my $smsg = bless {}, 'PublicInbox::Smsg';
-		$smsg->load_expand($doc);
-		my $blob = $smsg->{blob} // '(unset)';
-		if ($blob eq $oid) {
+		my $smsg = smsg_from_doc($doc);
+		my $blob = $smsg->{blob}; # may be undef if --skip-docdata
+		if (!defined($blob) || $blob eq $oid) {
 			$xdb->delete_document($num);
 		} else {
 			warn "E: #$num $oid != $blob in Xapian\n";
diff --git a/lib/PublicInbox/Smsg.pm b/lib/PublicInbox/Smsg.pm
index 171e0a00..14086538 100644
--- a/lib/PublicInbox/Smsg.pm
+++ b/lib/PublicInbox/Smsg.pm
@@ -15,13 +15,6 @@ our @EXPORT_OK = qw(subject_normalized);
 use PublicInbox::MID qw(mids);
 use PublicInbox::Address;
 use PublicInbox::MsgTime qw(msg_timestamp msg_datestamp);
-use Time::Local qw(timegm);
-
-sub get_val ($$) {
-	my ($doc, $col) = @_;
-	# sortable_unserialise is defined by PublicInbox::Search::load_xapian()
-	sortable_unserialise($doc->get_value($col));
-}
 
 sub to_doc_data {
 	my ($self) = @_;
@@ -61,17 +54,6 @@ sub load_from_data ($$) {
 	) = split(/\n/, $_[1]);
 }
 
-sub load_expand {
-	my ($self, $doc) = @_;
-	my $data = $doc->get_data or return;
-	$self->{ts} = get_val($doc, PublicInbox::Search::TS());
-	my $dt = get_val($doc, PublicInbox::Search::DT());
-	my ($yyyy, $mon, $dd, $hh, $mm, $ss) = unpack('A4A2A2A2A2A2', $dt);
-	$self->{ds} = timegm($ss, $mm, $hh, $dd, $mon - 1, $yyyy);
-	load_from_data($self, $data);
-	$self;
-}
-
 sub psgi_cull ($) {
 	my ($self) = @_;
 
diff --git a/t/search.t b/t/search.t
index 8df8a202..a66aec36 100644
--- a/t/search.t
+++ b/t/search.t
@@ -332,13 +332,13 @@ $ibx->with_umask(sub {
 		like($smsg->{to}, qr/\blist\@example\.com\b/, 'to appears');
 		my $doc = $m->get_document;
 		my $col = PublicInbox::Search::BYTES();
-		my $bytes = PublicInbox::Smsg::get_val($doc, $col);
+		my $bytes = PublicInbox::SearchIdx::get_val($doc, $col);
 		like($bytes, qr/\A[0-9]+\z/, '$bytes stored as digit');
 		ok($bytes > 0, '$bytes is > 0');
 		is($bytes, $smsg->{bytes}, 'bytes Xapian value matches Over');
 
 		$col = PublicInbox::Search::UID();
-		my $uid = PublicInbox::Smsg::get_val($doc, $col);
+		my $uid = PublicInbox::SearchIdx::get_val($doc, $col);
 		is($uid, $smsg->{num}, 'UID column matches {num}');
 		is($uid, $m->get_docid, 'UID column matches docid');
 	}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-24 10:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-24 10:13 [PATCH] searchidx: fix (undocumented) --skip-docdata handling Eric Wong

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://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

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index 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/

code repositories for the project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

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