about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-02-22 07:15:54 +0000
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-02-28 18:42:44 +0000
commit126d94b10886b02a3936f1429cab1eaea21b6025 (patch)
treedcaa2e2aa48fc1a42f832e335abd6a268357cae6 /lib/PublicInbox
parent61ecf6a904b868ce791115231b11859d725c6113 (diff)
downloadpublic-inbox-126d94b10886b02a3936f1429cab1eaea21b6025.tar.gz
Fortunately, Xapian multiple database support makes things
easier but we still need to handle the skeleton DB separately.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/Inbox.pm21
-rw-r--r--lib/PublicInbox/Search.pm42
2 files changed, 57 insertions, 6 deletions
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index e7856e3c..f000a950 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -73,6 +73,10 @@ sub new {
         _set_limiter($opts, $pi_config, 'httpbackend');
         _set_uint($opts, 'feedmax', 25);
         $opts->{nntpserver} ||= $pi_config->{'publicinbox.nntpserver'};
+        my $dir = $opts->{mainrepo};
+        if (defined $dir && -f "$dir/msgmap.sqlite3") { # XXX DIRTY
+                $opts->{version} = 2;
+        }
         bless $opts, $class;
 }
 
@@ -92,7 +96,12 @@ sub mm {
         my ($self) = @_;
         $self->{mm} ||= eval {
                 _cleanup_later($self);
-                PublicInbox::Msgmap->new($self->{mainrepo});
+                my $dir = $self->{mainrepo};
+                if (($self->{version} || 1) >= 2) {
+                        PublicInbox::Msgmap->new_file("$dir/msgmap.sqlite3");
+                } else {
+                        PublicInbox::Msgmap->new($dir);
+                }
         };
 }
 
@@ -100,7 +109,7 @@ sub search {
         my ($self) = @_;
         $self->{search} ||= eval {
                 _cleanup_later($self);
-                PublicInbox::Search->new($self->{mainrepo}, $self->{altid});
+                PublicInbox::Search->new($self, $self->{altid});
         };
 }
 
@@ -229,7 +238,7 @@ sub msg_by_smsg ($$;$) {
         # backwards compat to fallback to msg_by_mid
         # TODO: remove if we bump SCHEMA_VERSION in Search.pm:
         defined(my $blob = $smsg->{blob}) or
-                        return msg_by_mid($self, $smsg->mid);
+                        return msg_by_path($self, mid2path($smsg->mid), $ref);
 
         my $str = git($self)->cat_file($blob, $ref);
         $$str =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s if $str;
@@ -243,7 +252,11 @@ sub path_check {
 
 sub msg_by_mid ($$;$) {
         my ($self, $mid, $ref) = @_;
-        msg_by_path($self, mid2path($mid), $ref);
+        my $srch = search($self) or
+                        return msg_by_path($self, mid2path($mid), $ref);
+        my $smsg = $srch->lookup_skeleton($mid) or return;
+        $smsg->load_expand;
+        msg_by_smsg($self, $smsg, $ref);
 }
 
 1;
diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index 3b280598..b20b2ccd 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -144,7 +144,26 @@ sub new {
                 altid => $altid,
                 version => $version,
         }, $class;
-        $self->{xdb} = Search::Xapian::Database->new($self->xdir);
+        if ($version >= 2) {
+                my $dir = "$self->{mainrepo}/xap" . SCHEMA_VERSION;
+                my $xdb;
+                my $parts = 0;
+                foreach my $part (<$dir/*>) {
+                        -d $part && $part =~ m!/\d+\z! or next;
+                        $parts++;
+                        my $sub = Search::Xapian::Database->new($part);
+                        if ($xdb) {
+                                $xdb->add_database($sub);
+                        } else {
+                                $xdb = $sub;
+                        }
+                }
+                warn "v2 repo with $parts found in $dir\n";
+                $self->{xdb} = $xdb;
+                $self->{skel} = Search::Xapian::Database->new("$dir/all");
+        } else {
+                $self->{xdb} = Search::Xapian::Database->new($self->xdir);
+        }
         $self;
 }
 
@@ -166,7 +185,7 @@ sub query {
 
 sub get_thread {
         my ($self, $mid, $opts) = @_;
-        my $smsg = eval { $self->lookup_message($mid) };
+        my $smsg = eval { $self->lookup_skeleton($mid) };
 
         return { total => 0, msgs => [] } unless $smsg;
         my $qtid = Search::Xapian::Query->new('G' . $smsg->thread_id);
@@ -298,6 +317,25 @@ sub query_xover {
         _do_enquire($self, $query, {num => 1, limit => 200, offset => $offset});
 }
 
+sub lookup_skeleton {
+        my ($self, $mid) = @_;
+        my $skel = $self->{skel} or return lookup_message($self, $mid);
+        $mid = mid_clean($mid);
+        my $term = 'XMID' . $mid;
+        my $smsg;
+        my $beg = $skel->postlist_begin($term);
+        if ($beg != $skel->postlist_end($term)) {
+                my $doc_id = $beg->get_docid;
+                if (defined $doc_id) {
+                        # raises on error:
+                        my $doc = $skel->get_document($doc_id);
+                        $smsg = PublicInbox::SearchMsg->wrap($doc, $mid);
+                        $smsg->{doc_id} = $doc_id;
+                }
+        }
+        $smsg;
+}
+
 sub lookup_message {
         my ($self, $mid) = @_;
         $mid = mid_clean($mid);