From: "Eric Wong (Contractor, The Linux Foundation)" <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 02/21] v2/ui: some hacky things to get the PSGI UI to show up
Date: Wed, 28 Feb 2018 23:41:43 +0000 [thread overview]
Message-ID: <20180228234202.8839-3-e@80x24.org> (raw)
In-Reply-To: <20180228234202.8839-1-e@80x24.org>
Fortunately, Xapian multiple database support makes things
easier but we still need to handle the skeleton DB separately.
---
lib/PublicInbox/Inbox.pm | 21 +++++++++++++++++----
lib/PublicInbox/Search.pm | 42 ++++++++++++++++++++++++++++++++++++++++--
2 files changed, 57 insertions(+), 6 deletions(-)
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index e7856e3..f000a95 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 3b28059..b20b2cc 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);
--
EW
next prev parent reply other threads:[~2018-02-28 23:42 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-28 23:41 [PATCH v2 0/21] UI bits and v2 import fixes Eric Wong (Contractor, The Linux Foundation)
2018-02-28 23:41 ` [PATCH 01/21] v2writable: warn on duplicate Message-IDs Eric Wong (Contractor, The Linux Foundation)
2018-02-28 23:41 ` Eric Wong (Contractor, The Linux Foundation) [this message]
2018-02-28 23:41 ` [PATCH 03/21] v2/ui: retry DB reopens in a few more places Eric Wong (Contractor, The Linux Foundation)
2018-02-28 23:41 ` [PATCH 04/21] v2writable: cleanup unused pipes in partitions Eric Wong (Contractor, The Linux Foundation)
2018-02-28 23:41 ` [PATCH 05/21] searchidxpart: binmode Eric Wong (Contractor, The Linux Foundation)
2018-02-28 23:41 ` [PATCH 06/21] use PublicInbox::MIME consistently Eric Wong (Contractor, The Linux Foundation)
2018-02-28 23:41 ` [PATCH 07/21] searchidxpart: chomp line before splitting Eric Wong (Contractor, The Linux Foundation)
2018-02-28 23:41 ` [PATCH 08/21] searchidx*: name child subprocesses Eric Wong (Contractor, The Linux Foundation)
2018-02-28 23:41 ` [PATCH 09/21] searchidx: get rid of pointless index_blob wrapper Eric Wong (Contractor, The Linux Foundation)
2018-02-28 23:41 ` [PATCH 10/21] view: remove X-PI-TS reference Eric Wong (Contractor, The Linux Foundation)
2018-02-28 23:41 ` [PATCH 11/21] searchidxthread: load doc data for references Eric Wong (Contractor, The Linux Foundation)
2018-02-28 23:41 ` [PATCH 12/21] searchidxpart: force integers into add_message Eric Wong (Contractor, The Linux Foundation)
2018-02-28 23:41 ` [PATCH 13/21] search: reopen skeleton DB as well Eric Wong (Contractor, The Linux Foundation)
2018-02-28 23:41 ` [PATCH 14/21] searchidx: index values in the threader Eric Wong (Contractor, The Linux Foundation)
2018-02-28 23:41 ` [PATCH 15/21] search: use different Enquire object for skeleton queries Eric Wong (Contractor, The Linux Foundation)
2018-02-28 23:41 ` [PATCH 16/21] rename SearchIdxThread to SearchIdxSkeleton Eric Wong (Contractor, The Linux Foundation)
2018-02-28 23:41 ` [PATCH 17/21] v2writable: commit to skeleton via remote partitions Eric Wong (Contractor, The Linux Foundation)
2018-02-28 23:41 ` [PATCH 18/21] searchidxskeleton: extra error checking Eric Wong (Contractor, The Linux Foundation)
2018-02-28 23:42 ` [PATCH 19/21] searchidx: do not modify Xapian DB while iterating Eric Wong (Contractor, The Linux Foundation)
2018-02-28 23:42 ` [PATCH 20/21] search: query_xover uses skeleton DB iff available Eric Wong (Contractor, The Linux Foundation)
2018-02-28 23:42 ` [PATCH 21/21] v2/ui: get nntpd and init tests running on v2 Eric Wong (Contractor, The Linux Foundation)
2018-03-01 23:40 ` [PATCH v2 0/21] UI bits and v2 import fixes Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180228234202.8839-3-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).