]> Sergey Matveev's repositories - public-inbox.git/commitdiff
searchidx: rename get_val to int_val and return IV
authorEric Wong <e@80x24.org>
Mon, 21 Dec 2020 07:51:21 +0000 (07:51 +0000)
committerEric Wong <e@80x24.org>
Mon, 21 Dec 2020 21:51:58 +0000 (21:51 +0000)
Values can be strings in Xapian, although we currently use
integer values exclusively.  Give the wrapper a more appropriate
name in case we start using string columns.

For future-proofing, we'll now return `undef' on missing columns
and coerce the return value to an IV (integer value) to save
memory, as sortable_unserialise returns a PV (pointer value)
scalar despite it existing to support numeric values.

lib/PublicInbox/SearchIdx.pm
t/search.t

index b731f6982f8bd1e6d44179d26a94f32c67726ae7..cf2c2c55e381c1ca1f926198c8e8c9d13aae4161 100644 (file)
@@ -501,17 +501,18 @@ sub remove_eidx_info {
        $self->{xdb}->replace_document($docid, $doc);
 }
 
-sub get_val ($$) {
+sub int_val ($$) {
        my ($doc, $col) = @_;
-       sortable_unserialise($doc->get_value($col));
+       my $val = $doc->get_value($col) or return; # undefined is '' in Xapian
+       sortable_unserialise($val) + 0; # PV => IV conversion
 }
 
 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());
+       $smsg->{ts} = int_val($doc, PublicInbox::Search::TS());
+       my $dt = int_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);
index da9acb07623989d57bf653207a650897bbb86f20..111432043ed8ece5e37edb8843450f0fb42e9bcf 100644 (file)
@@ -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::SearchIdx::get_val($doc, $col);
+               my $bytes = PublicInbox::SearchIdx::int_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::SearchIdx::get_val($doc, $col);
+               my $uid = PublicInbox::SearchIdx::int_val($doc, $col);
                is($uid, $smsg->{num}, 'UID column matches {num}');
                is($uid, $m->get_docid, 'UID column matches docid');
        }