user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] searchidx: fix (undocumented) --skip-docdata handling
Date: Thu, 24 Sep 2020 10:13:39 +0000	[thread overview]
Message-ID: <20200924101339.8910-1-e@80x24.org> (raw)

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');
 	}

                 reply	other threads:[~2020-09-24 10:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20200924101339.8910-1-e@80x24.org \
    --to=e@80x24.org \
    --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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).