]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Search.pm
search: reduce columns stored in Xapian
[public-inbox.git] / lib / PublicInbox / Search.pm
index 6f5e0624a4a5986369f12de95d81f6fe3a01fbf4..ca389e320b2706edacbbd578b33dacc65812dece 100644 (file)
@@ -8,12 +8,9 @@ use strict;
 use warnings;
 
 # values for searching
-use constant DS => 0; # Date: header in Unix time
-use constant NUM => 1; # NNTP article number
-use constant BYTES => 2; # :bytes as defined in RFC 3977
-use constant LINES => 3; # :lines as defined in RFC 3977
-use constant TS => 4;  # Received: header in Unix time
-use constant YYYYMMDD => 5; # for searching in the WWW UI
+use constant TS => 0;  # Received: header in Unix time
+use constant YYYYMMDD => 1; # for searching in the WWW UI
+use constant NUM => 2; # NNTP article number
 
 use Search::Xapian qw/:standard/;
 use PublicInbox::SearchMsg;
@@ -215,18 +212,20 @@ sub get_thread {
 sub retry_reopen {
        my ($self, $cb) = @_;
        my $ret;
-       for (1..10) {
+       for my $i (1..10) {
                eval { $ret = $cb->() };
                return $ret unless $@;
                # Exception: The revision being read has been discarded -
                # you should call Xapian::Database::reopen()
                if (ref($@) eq 'Search::Xapian::DatabaseModifiedError') {
+                       warn "reopen try #$i on $@\n";
                        reopen($self);
                } else {
                        warn "ref: ", ref($@), "\n";
                        die;
                }
        }
+       die "Too many Xapian database modifications in progress\n";
 }
 
 sub _do_enquire {
@@ -348,36 +347,34 @@ sub query_ts {
 sub first_smsg_by_mid {
        my ($self, $mid) = @_;
        my $smsg;
-       each_smsg_by_mid($self, $mid, sub { $smsg = $_[0]; undef });
+       retry_reopen($self, sub {
+               each_smsg_by_mid($self, $mid, sub { $smsg = $_[0]; undef });
+       });
        $smsg;
 }
 
 sub lookup_article {
        my ($self, $num) = @_;
        my $term = 'XNUM'.$num;
-       my $smsg;
-       eval {
-               retry_reopen($self, sub {
-                       my $db = $self->{skel} || $self->{xdb};
-                       my $head = $db->postlist_begin($term);
-                       my $tail = $db->postlist_end($term);
-                       return if $head->equal($tail);
-                       my $doc_id = $head->get_docid;
-                       return unless defined $doc_id;
-                       $head->inc;
-                       if ($head->nequal($tail)) {
-                               my $loc= $self->{mainrepo} .
-                                       ($self->{skel} ? 'skel' : 'xdb');
-                               warn "article #$num is not unique in $loc\n";
-                       }
-                       # raises on error:
-                       my $doc = $db->get_document($doc_id);
-                       $smsg = PublicInbox::SearchMsg->wrap($doc);
-                       $smsg->load_expand;
-                       $smsg->{doc_id} = $doc_id;
-               });
-       };
-       $smsg;
+       my $db = $self->{skel} || $self->{xdb};
+       retry_reopen($self, sub {
+               my $head = $db->postlist_begin($term);
+               my $tail = $db->postlist_end($term);
+               return if $head->equal($tail);
+               my $doc_id = $head->get_docid;
+               return unless defined $doc_id;
+               $head->inc;
+               if ($head->nequal($tail)) {
+                       my $loc= $self->{mainrepo} .
+                               ($self->{skel} ? 'skel' : 'xdb');
+                       warn "article #$num is not unique in $loc\n";
+               }
+               # raises on error:
+               my $doc = $db->get_document($doc_id);
+               my $smsg = PublicInbox::SearchMsg->wrap($doc);
+               $smsg->{doc_id} = $doc_id;
+               $smsg->load_expand;
+       });
 }
 
 sub each_smsg_by_mid {