]> Sergey Matveev's repositories - public-inbox.git/commitdiff
searchmsg: remove ensure_metadata
authorEric Wong <e@80x24.org>
Tue, 20 Dec 2016 03:03:57 +0000 (03:03 +0000)
committerEric Wong <e@80x24.org>
Tue, 20 Dec 2016 08:24:25 +0000 (08:24 +0000)
Instead, only preload the ->mid field for threading,
as we only need ->thread and ->path once in Search->get_thread
(but we will need the ->mid field repeatedly).

This more than doubles View->load_results performance on
according to thread-all on an inbox with over 300K messages.

lib/PublicInbox/Search.pm
lib/PublicInbox/SearchMsg.pm
lib/PublicInbox/View.pm
t/search.t

index 24cb26670754b2f4a21b62e7d22c3cdc76098a5a..d4f6f77a548f79acedfaf0b0de2a5b640dcaf017 100644 (file)
@@ -108,12 +108,6 @@ my %all_pfx = (%bool_pfx_internal, %bool_pfx_external, %prob_prefix);
 
 sub xpfx { $all_pfx{$_[0]} }
 
-our %PFX2TERM_RMAP;
-my %meta_pfx = (mid => 1, thread => 1, path => 1);
-while (my ($k, $v) = each %all_pfx) {
-       $PFX2TERM_RMAP{$v} = $k if $meta_pfx{$k};
-}
-
 my $mail_query = Search::Xapian::Query->new(xpfx('type') . 'mail');
 
 sub xdir {
index d62f02c8487f6baebfd783701d5fe67ec79b69fe..96406c6f9296646ff9534f211eefa461541b7c83 100644 (file)
@@ -10,7 +10,6 @@ use Search::Xapian;
 use Date::Parse qw/str2time/;
 use PublicInbox::MID qw/mid_clean/;
 use PublicInbox::Address;
-our $PFX2TERM_RE = undef;
 
 sub new {
        my ($class, $mime) = @_;
@@ -121,29 +120,17 @@ sub references {
        defined $x ? $x : '';
 }
 
-sub ensure_metadata {
-       my ($self) = @_;
+sub _get_term_val ($$$) {
+       my ($self, $pfx, $re) = @_;
        my $doc = $self->{doc};
        my $end = $doc->termlist_end;
-
-       unless (defined $PFX2TERM_RE) {
-               my $or = join('|', keys %PublicInbox::Search::PFX2TERM_RMAP);
-               $PFX2TERM_RE = qr/\A($or)/;
-       }
-
-       while (my ($pfx, $field) = each %PublicInbox::Search::PFX2TERM_RMAP) {
-               # ideally we'd move this out of the loop:
-               my $i = $doc->termlist_begin;
-
-               $i->skip_to($pfx);
-               if ($i != $end) {
-                       my $val = $i->get_termname;
-
-                       if ($val =~ s/$PFX2TERM_RE//o) {
-                               $self->{$field} = $val;
-                       }
-               }
+       my $i = $doc->termlist_begin;
+       $i->skip_to($pfx);
+       if ($i != $end) {
+               my $val = $i->get_termname;
+               $val =~ s/$re// and return $val;
        }
+       undef;
 }
 
 sub mid ($;$) {
@@ -154,8 +141,8 @@ sub mid ($;$) {
        } elsif (my $rv = $self->{mid}) {
                $rv;
        } else {
-               $self->ensure_metadata; # needed for ghosts
-               $self->{mid} ||= $self->_extract_mid;
+               $self->{mid} = _get_term_val($self, 'Q', qr/\AQ/) ||
+                               $self->_extract_mid;
        }
 }
 
@@ -194,16 +181,14 @@ sub thread_id {
        my ($self) = @_;
        my $tid = $self->{thread};
        return $tid if defined $tid;
-       $self->ensure_metadata;
-       $self->{thread};
+       $self->{thread} = _get_term_val($self, 'G', qr/\AG/); # *G*roup
 }
 
 sub path {
        my ($self) = @_;
        my $path = $self->{path};
        return $path if defined $path;
-       $self->ensure_metadata;
-       $self->{path};
+       $self->{path} = _get_term_val($self, 'XPATH', qr/\AXPATH/); # path
 }
 
 1;
index fa47a16a3d3d40087a0390e8d03ed937c18f88db..a50cb642373ad1f9eea336e119180128d674e15e 100644 (file)
@@ -737,7 +737,7 @@ sub indent_for {
 sub load_results {
        my ($srch, $sres) = @_;
        my $msgs = delete $sres->{msgs};
-       $srch->retry_reopen(sub { [ map { $_->ensure_metadata; $_ } @$msgs ] });
+       $srch->retry_reopen(sub { [ map { $_->mid; $_ } @$msgs ] });
 }
 
 sub msg_timestamp {
index eed9c9b61593a9e0e8694466b2c2e85f007fe399..c16811d8d462806886c5d6f06e54d09c8dd0f6ba 100644 (file)
@@ -109,7 +109,6 @@ sub filter_mids {
        my $found = $ro->lookup_message('<root@s>');
        ok($found, "message found");
        is($root_id, $found->{doc_id}, 'doc_id set correctly');
-       $found->ensure_metadata;
        is($found->mid, 'root@s', 'mid set correctly');
        ok(int($found->thread_id) > 0, 'thread_id is an integer');
 
@@ -290,7 +289,6 @@ sub filter_mids {
                body => "LOOP!\n"));
        ok($doc_id > 0, "doc_id defined with circular reference");
        my $smsg = $rw->lookup_message('circle@a');
-       $smsg->ensure_metadata;
        is($smsg->references, '', "no references created");
        my $msg = PublicInbox::SearchMsg->load_doc($smsg->{doc});
        is($s, $msg->subject, 'long subject not rewritten');