about summary refs log tree commit homepage
path: root/lib/PublicInbox/SearchIdx.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-09-24 10:13:39 +0000
committerEric Wong <e@80x24.org>2020-09-24 21:18:44 +0000
commit2255a4ad2fa2384c1f4cec6dd267383396cbc945 (patch)
treee5d00c41abb08184d0b44584822a1e8160d82ac0 /lib/PublicInbox/SearchIdx.pm
parent8d7216a0c278272d7d3525f4bb0ec1fa74486698 (diff)
downloadpublic-inbox-2255a4ad2fa2384c1f4cec6dd267383396cbc945.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox/SearchIdx.pm')
-rw-r--r--lib/PublicInbox/SearchIdx.pm26
1 files changed, 22 insertions, 4 deletions
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";