From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/6] www: use Inbox->over where appropriate
Date: Wed, 15 May 2019 06:33:51 +0000 [thread overview]
Message-ID: <20190515063354.52259-4-e@80x24.org> (raw)
In-Reply-To: <20190515063354.52259-1-e@80x24.org>
We don't need to rely on Xapian search functionality for the
majority of the WWW code, even. subject_normalized is moved to
SearchMsg, where it (probably) makes more sense, anyways.
---
lib/PublicInbox/Feed.pm | 11 ++++----
lib/PublicInbox/Inbox.pm | 1 +
lib/PublicInbox/Mbox.pm | 25 +++++++++--------
lib/PublicInbox/OverIdx.pm | 13 +++++++--
lib/PublicInbox/Search.pm | 30 --------------------
lib/PublicInbox/SearchMsg.pm | 14 +++++++++
lib/PublicInbox/SearchView.pm | 13 +++++----
lib/PublicInbox/View.pm | 53 ++++++++++++++++-------------------
lib/PublicInbox/WWW.pm | 32 ++++++---------------
t/search.t | 4 +--
t/v2writable.t | 2 +-
t/view.t | 1 +
12 files changed, 90 insertions(+), 109 deletions(-)
diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index b373a1e..a04838a 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -27,10 +27,10 @@ sub generate {
sub generate_thread_atom {
my ($ctx) = @_;
my $mid = $ctx->{mid};
- my $msgs = $ctx->{srch}->get_thread($mid);
+ my $ibx = $ctx->{-inbox};
+ my $msgs = $ibx->over->get_thread($mid);
return _no_thread() unless @$msgs;
- my $ibx = $ctx->{-inbox};
my $html_url = $ibx->base_url($ctx->{env});
$html_url .= PublicInbox::Hval->new_msgid($mid)->{href};
$ctx->{-html_url} = $html_url;
@@ -46,12 +46,13 @@ sub generate_html_index {
# if the 'r' query parameter is given, it is a legacy permalink
# which we must continue supporting:
my $qp = $ctx->{qp};
- if ($qp && !$qp->{r} && $ctx->{srch}) {
+ my $ibx = $ctx->{-inbox};
+ if ($qp && !$qp->{r} && $ibx->over) {
return PublicInbox::View::index_topics($ctx);
}
my $env = $ctx->{env};
- my $url = $ctx->{-inbox}->base_url($env) . 'new.html';
+ my $url = $ibx->base_url($env) . 'new.html';
my $qs = $env->{QUERY_STRING};
$url .= "?$qs" if $qs ne '';
[302, [ 'Location', $url, 'Content-Type', 'text/plain'],
@@ -94,7 +95,7 @@ sub recent_msgs {
if ($v > 2) {
die "BUG: unsupported inbox version: $v\n";
}
- if (my $srch = $ibx->search) {
+ if ($ibx->over) {
return PublicInbox::View::paginate_recent($ctx, $max);
}
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index e3bc104..dc186b7 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -172,6 +172,7 @@ sub search ($;$) {
my ($self, $over_only) = @_;
my $srch = $self->{search} ||= eval {
_cleanup_later($self);
+ require PublicInbox::Search;
PublicInbox::Search->new($self, $self->{altid});
};
# TODO: lazily load Xapian
diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm
index 78dbe27..15200d3 100644
--- a/lib/PublicInbox/Mbox.pm
+++ b/lib/PublicInbox/Mbox.pm
@@ -45,7 +45,7 @@ sub getline {
}
$cur = $next or return;
my $ibx = $ctx->{-inbox};
- $next = $ibx->search->next_by_mid($ctx->{mid}, \$id, \$prev);
+ $next = $ibx->over->next_by_mid($ctx->{mid}, \$id, \$prev);
@$more = ($ctx, $id, $prev, $next); # $next may be undef, here
my $mref = $ibx->msg_by_smsg($cur) or return;
msg_str($ctx, Email::Simple->new($mref));
@@ -59,12 +59,12 @@ sub emit_raw {
my $ibx = $ctx->{-inbox};
my $first;
my $more;
- if (my $srch = $ibx->search) {
+ if (my $over = $ibx->over) {
my ($id, $prev);
- my $smsg = $srch->next_by_mid($mid, \$id, \$prev) or return;
+ my $smsg = $over->next_by_mid($mid, \$id, \$prev) or return;
my $mref = $ibx->msg_by_smsg($smsg) or return;
$first = Email::Simple->new($mref);
- my $next = $srch->next_by_mid($mid, \$id, \$prev);
+ my $next = $over->next_by_mid($mid, \$id, \$prev);
# $more is for ->getline
$more = [ $ctx, $id, $prev, $next, $first ] if $next;
} else {
@@ -130,11 +130,11 @@ sub msg_str {
}
sub thread_mbox {
- my ($ctx, $srch, $sfx) = @_;
+ my ($ctx, $over, $sfx) = @_;
eval { require IO::Compress::Gzip };
return sub { need_gzip(@_) } if $@;
my $mid = $ctx->{mid};
- my $msgs = $srch->get_thread($mid, {});
+ my $msgs = $over->get_thread($mid, {});
return [404, [qw(Content-Type text/plain)], []] if !@$msgs;
my $prev = $msgs->[-1];
my $i = 0;
@@ -144,7 +144,7 @@ sub thread_mbox {
return $smsg;
}
# refill result set
- $msgs = $srch->get_thread($mid, $prev);
+ $msgs = $over->get_thread($mid, $prev);
return unless @$msgs;
$prev = $msgs->[-1];
$i = 0;
@@ -168,17 +168,19 @@ sub emit_range {
sub mbox_all_ids {
my ($ctx) = @_;
my $prev = 0;
- my $ids = $ctx->{-inbox}->mm->ids_after(\$prev) or return
+ my $ibx = $ctx->{-inbox};
+ my $ids = $ibx->mm->ids_after(\$prev) or return
[404, [qw(Content-Type text/plain)], ["No results found\n"]];
my $i = 0;
- my $over = $ctx->{srch}->{over_ro};
+ my $over = $ibx->over or
+ return PublicInbox::WWW::need($ctx, 'Overview');
my $cb = sub {
do {
while ((my $num = $ids->[$i++])) {
my $smsg = $over->get_art($num) or next;
return $smsg;
}
- $ids = $ctx->{-inbox}->mm->ids_after(\$prev);
+ $ids = $ibx->mm->ids_after(\$prev);
$i = 0;
} while (@$ids);
undef;
@@ -193,7 +195,8 @@ sub mbox_all {
return sub { need_gzip(@_) } if $@;
return mbox_all_ids($ctx) if $query eq '';
my $opts = { mset => 2 };
- my $srch = $ctx->{srch};
+ my $srch = $ctx->{-inbox}->search or
+ return PublicInbox::WWW::need($ctx, 'Search');;
my $mset = $srch->query($query, $opts);
$opts->{offset} = $mset->size or
return [404, [qw(Content-Type text/plain)],
diff --git a/lib/PublicInbox/OverIdx.pm b/lib/PublicInbox/OverIdx.pm
index bb3068d..9fc51e5 100644
--- a/lib/PublicInbox/OverIdx.pm
+++ b/lib/PublicInbox/OverIdx.pm
@@ -14,7 +14,7 @@ use base qw(PublicInbox::Over);
use IO::Handle;
use DBI qw(:sql_types); # SQL_BLOB
use PublicInbox::MID qw/id_compress mids references/;
-use PublicInbox::SearchMsg;
+use PublicInbox::SearchMsg qw(subject_normalized);
use Compress::Zlib qw(compress);
use PublicInbox::Search;
@@ -237,6 +237,15 @@ sub parse_references ($$$) {
\@keep;
}
+# normalize subjects so they are suitable as pathnames for URLs
+# XXX: consider for removal
+sub subject_path ($) {
+ my ($subj) = @_;
+ $subj = subject_normalized($subj);
+ $subj =~ s![^a-zA-Z0-9_\.~/\-]+!_!g;
+ lc($subj);
+}
+
sub add_overview {
my ($self, $mime, $bytes, $num, $oid, $mid0) = @_;
my $lines = $mime->body_raw =~ tr!\n!\n!;
@@ -252,7 +261,7 @@ sub add_overview {
my $subj = $smsg->subject;
my $xpath;
if ($subj ne '') {
- $xpath = PublicInbox::Search::subject_path($subj);
+ $xpath = subject_path($subj);
$xpath = id_compress($xpath);
}
my $dd = $smsg->to_doc_data($oid, $mid0);
diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index 760c660..e79ec0f 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -20,7 +20,6 @@ use PublicInbox::Over;
# This is English-only, everything else is non-standard and may be confused as
# a prefix common in patch emails
-our $REPLY_RE = qr/^re:\s+/i;
our $LANG = 'english';
use constant {
@@ -182,11 +181,6 @@ sub query {
}
}
-sub get_thread {
- my ($self, $mid, $prev) = @_;
- $self->{over_ro}->get_thread($mid, $prev);
-}
-
sub retry_reopen {
my ($self, $cb) = @_;
for my $i (1..10) {
@@ -298,30 +292,6 @@ sub lookup_article {
$self->{over_ro}->get_art($num);
}
-sub next_by_mid {
- my ($self, $mid, $id, $prev) = @_;
- $self->{over_ro}->next_by_mid($mid, $id, $prev);
-}
-
-# normalize subjects so they are suitable as pathnames for URLs
-# XXX: consider for removal
-sub subject_path {
- my $subj = pop;
- $subj = subject_normalized($subj);
- $subj =~ s![^a-zA-Z0-9_\.~/\-]+!_!g;
- lc($subj);
-}
-
-sub subject_normalized {
- my $subj = pop;
- $subj =~ s/\A\s+//s; # no leading space
- $subj =~ s/\s+\z//s; # no trailing space
- $subj =~ s/\s+/ /gs; # no redundant spaces
- $subj =~ s/\.+\z//; # no trailing '.'
- $subj =~ s/$REPLY_RE//igo; # remove reply prefix
- $subj;
-}
-
sub help {
my ($self) = @_;
$self->qp; # parse altids
diff --git a/lib/PublicInbox/SearchMsg.pm b/lib/PublicInbox/SearchMsg.pm
index ceb6eda..5f3c8af 100644
--- a/lib/PublicInbox/SearchMsg.pm
+++ b/lib/PublicInbox/SearchMsg.pm
@@ -8,6 +8,8 @@
package PublicInbox::SearchMsg;
use strict;
use warnings;
+use base qw(Exporter);
+our @EXPORT_OK = qw(subject_normalized);
use PublicInbox::MID qw/mid_clean mid_mime/;
use PublicInbox::Address;
use PublicInbox::MsgTime qw(msg_timestamp msg_datestamp);
@@ -185,4 +187,16 @@ sub mid ($;$) {
sub _extract_mid { mid_clean(mid_mime($_[0]->{mime})) }
+our $REPLY_RE = qr/^re:\s+/i;
+
+sub subject_normalized ($) {
+ my ($subj) = @_;
+ $subj =~ s/\A\s+//s; # no leading space
+ $subj =~ s/\s+\z//s; # no trailing space
+ $subj =~ s/\s+/ /gs; # no redundant spaces
+ $subj =~ s/\.+\z//; # no trailing '.'
+ $subj =~ s/$REPLY_RE//igo; # remove reply prefix
+ $subj;
+}
+
1;
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index 3b3afde..6592b3b 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -29,6 +29,8 @@ sub mbox_results {
sub sres_top_html {
my ($ctx) = @_;
+ my $srch = $ctx->{-inbox}->search or
+ return PublicInbox::WWW::need($ctx, 'Search');
my $q = PublicInbox::SearchQuery->new($ctx->{qp});
my $x = $q->{x};
my $query = $q->{'q'};
@@ -44,7 +46,7 @@ sub sres_top_html {
my ($mset, $total, $err, $cb);
retry:
eval {
- $mset = $ctx->{srch}->query($query, $opts);
+ $mset = $srch->query($query, $opts);
$total = $mset->get_matches_estimated;
};
$err = $@;
@@ -98,8 +100,8 @@ sub mset_summary {
my $pad = length("$total");
my $pfx = ' ' x $pad;
my $res = \($ctx->{-html_tip});
- my $srch = $ctx->{srch};
my $ibx = $ctx->{-inbox};
+ my $srch = $ibx->search;
my $obfs_ibx = $ibx->{obfuscate} ? $ibx : undef;
foreach my $m ($mset->items) {
my $rank = sprintf("%${pad}d", $m->get_rank + 1);
@@ -220,8 +222,8 @@ sub sort_relevance {
sub mset_thread {
my ($ctx, $mset, $q) = @_;
my %pct;
- my $srch = $ctx->{srch};
- my $msgs = $srch->retry_reopen(sub { [ map {
+ my $ibx = $ctx->{-inbox};
+ my $msgs = $ibx->search->retry_reopen(sub { [ map {
my $i = $_;
my $smsg = PublicInbox::SearchMsg->load_doc($i->get_document);
$pct{$smsg->mid} = $i->get_percent;
@@ -232,7 +234,6 @@ sub mset_thread {
$r ? sort_relevance(\%pct) : *PublicInbox::View::sort_ds,
$ctx);
my $skel = search_nav_bot($mset, $q). "<pre>";
- my $ibx = $ctx->{-inbox};
$ctx->{-upfx} = '';
$ctx->{anchor_idx} = 1;
$ctx->{cur_level} = 0;
@@ -286,7 +287,7 @@ sub adump {
my $ibx = $ctx->{-inbox};
my @items = $mset->items;
$ctx->{search_query} = $q;
- my $srch = $ctx->{srch};
+ my $srch = $ibx->search;
PublicInbox::WwwAtomStream->response($ctx, 200, sub {
while (my $x = shift @items) {
$x = load_doc_retry($srch, $x);
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 47a2046..09afdaf 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -18,7 +18,7 @@ use PublicInbox::Reply;
use PublicInbox::ViewDiff qw(flush_diff);
require POSIX;
use Time::Local qw(timegm);
-
+use PublicInbox::SearchMsg qw(subject_normalized);
use constant COLS => 72;
use constant INDENT => ' ';
use constant TCHILD => '` ';
@@ -63,12 +63,12 @@ sub msg_page {
my $ibx = $ctx->{-inbox};
my ($first, $more);
my $smsg;
- if (my $srch = $ibx->search) {
+ if (my $over = $ibx->over) {
my ($id, $prev);
- $smsg = $srch->next_by_mid($mid, \$id, \$prev);
+ $smsg = $over->next_by_mid($mid, \$id, \$prev);
$first = $ibx->msg_by_smsg($smsg) if $smsg;
if ($first) {
- my $next = $srch->next_by_mid($mid, \$id, \$prev);
+ my $next = $over->next_by_mid($mid, \$id, \$prev);
$more = [ $id, $prev, $next ] if $next;
}
return unless $first;
@@ -85,7 +85,7 @@ sub msg_html_more {
my $mid = $ctx->{mid};
my $ibx = $ctx->{-inbox};
$smsg = $ibx->smsg_mime($smsg);
- my $next = $ctx->{srch}->next_by_mid($mid, \$id, \$prev);
+ my $next = $ibx->over->next_by_mid($mid, \$id, \$prev);
@$more = $next ? ($id, $prev, $next) : ();
if ($smsg) {
my $mime = $smsg->{mime};
@@ -203,7 +203,6 @@ sub nr_to_s ($$$) {
# this is already inside a <pre>
sub index_entry {
my ($smsg, $ctx, $more) = @_;
- my $srch = $ctx->{srch};
my $subj = $smsg->subject;
my $mid_raw = $smsg->mid;
my $id = id_compress($mid_raw, 1);
@@ -440,8 +439,8 @@ sub stream_thread ($$) {
sub thread_html {
my ($ctx) = @_;
my $mid = $ctx->{mid};
- my $srch = $ctx->{srch};
- my ($nr, $msgs) = $srch->get_thread($mid);
+ my $ibx = $ctx->{-inbox};
+ my ($nr, $msgs) = $ibx->over->get_thread($mid);
return missing_thread($ctx) if $nr == 0;
my $skel = '<hr><pre>';
$skel .= $nr == 1 ? 'only message in thread' : 'end of thread';
@@ -464,7 +463,6 @@ sub thread_html {
my $rootset = thread_results($ctx, $msgs);
# reduce hash lookups in pre_thread->skel_dump
- my $ibx = $ctx->{-inbox};
$ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
walk_thread($rootset, $ctx, *pre_thread);
@@ -627,8 +625,8 @@ sub add_text_body {
sub _msg_html_prepare {
my ($hdr, $ctx, $more, $nr) = @_;
- my $srch = $ctx->{srch} if $ctx;
my $atom = '';
+ my $over = $ctx->{-inbox}->over;
my $obfs_ibx = $ctx->{-obfs_ibx};
my $rv = '';
my $mids = mids($hdr);
@@ -642,7 +640,7 @@ sub _msg_html_prepare {
} else {
$rv .= '<pre>';
}
- if ($srch) {
+ if ($over) {
$ctx->{-upfx} = '../';
}
my @title;
@@ -668,14 +666,14 @@ sub _msg_html_prepare {
if (defined($v = $hdr->header('Subject')) && ($v ne '')) {
$v = ascii_html($v);
obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx;
- if ($srch) {
+ if ($over) {
$rv .= qq(Subject: <a\nhref="#r"\nid=t>$v</a>\n);
} else {
$rv .= "Subject: $v\n";
}
$title[0] = $v;
} else { # dummy anchor for thread skeleton at bottom of page
- $rv .= qq(<a\nhref="#r"\nid=t></a>) if $srch;
+ $rv .= qq(<a\nhref="#r"\nid=t></a>) if $over;
$title[0] = '(no subject)';
}
if (defined($v = $hdr->header('Date'))) {
@@ -698,15 +696,15 @@ sub _msg_html_prepare {
$rv .= "(<a\nhref=\"raw\">raw</a>)\n";
}
}
- $rv .= _parent_headers($hdr, $srch);
+ $rv .= _parent_headers($hdr, $over);
$rv .= "\n";
}
sub thread_skel {
my ($dst, $ctx, $hdr, $tpfx) = @_;
- my $srch = $ctx->{srch};
my $mid = mids($hdr)->[0];
- my ($nr, $msgs) = $srch->get_thread($mid);
+ my $ibx = $ctx->{-inbox};
+ my ($nr, $msgs) = $ibx->over->get_thread($mid);
my $expand = qq(expand[<a\nhref="${tpfx}T/#u">flat</a>) .
qq(|<a\nhref="${tpfx}t/#u">nested</a>] ) .
qq(<a\nhref="${tpfx}t.mbox.gz">mbox.gz</a> ) .
@@ -732,14 +730,13 @@ sub thread_skel {
my $subj = $hdr->header('Subject');
defined $subj or $subj = '';
$subj = '(no subject)' if $subj eq '';
- $ctx->{prev_subj} = [ split(/ /, $srch->subject_normalized($subj)) ];
+ $ctx->{prev_subj} = [ split(/ /, subject_normalized($subj)) ];
$ctx->{cur} = $mid;
$ctx->{prev_attr} = '';
$ctx->{prev_level} = 0;
$ctx->{dst} = $dst;
# reduce hash lookups in skel_dump
- my $ibx = $ctx->{-inbox};
$ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
walk_thread(thread_results($ctx, $msgs), $ctx, *skel_dump);
@@ -747,7 +744,7 @@ sub thread_skel {
}
sub _parent_headers {
- my ($hdr, $srch) = @_;
+ my ($hdr, $over) = @_;
my $rv = '';
my $refs = references($hdr);
@@ -762,10 +759,10 @@ sub _parent_headers {
# do not display References: if search is present,
# we show the thread skeleton at the bottom, instead.
- return $rv if $srch;
+ return $rv if $over;
if (@$refs) {
- @$refs = map { linkify_ref_nosrch($_) } @$refs;
+ @$refs = map { linkify_ref_no_over($_) } @$refs;
$rv .= 'References: '. join("\n\t", @$refs) . "\n";
}
$rv;
@@ -774,12 +771,12 @@ sub _parent_headers {
sub html_footer {
my ($hdr, $standalone, $ctx, $rhref) = @_;
- my $srch = $ctx->{srch} if $ctx;
+ my $ibx = $ctx->{-inbox} if $ctx;
my $upfx = '../';
my $tpfx = '';
my $idx = $standalone ? " <a\nhref=\"$upfx\">index</a>" : '';
my $irt = '';
- if ($idx && $srch) {
+ if ($idx && $ibx->over) {
$idx .= "\n";
thread_skel(\$idx, $ctx, $hdr, $tpfx);
my ($next, $prev);
@@ -819,7 +816,7 @@ sub html_footer {
$irt .= $idx;
}
-sub linkify_ref_nosrch {
+sub linkify_ref_no_over {
my $v = PublicInbox::Hval->new_msgid($_[0]);
my $html = $v->as_html;
my $href = $v->{href};
@@ -965,7 +962,7 @@ sub skel_dump {
# Subject is never undef, this mail was loaded from
# our Xapian which would've resulted in '' if it were
# really missing (and Filter rejects empty subjects)
- my @subj = split(/ /, $ctx->{srch}->subject_normalized($smsg->subject));
+ my @subj = split(/ /, subject_normalized($smsg->subject));
# remove common suffixes from the subject if it matches the previous,
# so we do not show redundant text at the end.
@@ -1034,14 +1031,13 @@ sub sort_ds {
# returns 200 if done, 404 if not
sub acc_topic {
my ($ctx, $level, $node) = @_;
- my $srch = $ctx->{srch};
my $mid = $node->{id};
my $x = $node->{smsg} || $ctx->{-inbox}->smsg_by_mid($mid);
my ($subj, $ds);
my $topic;
if ($x) {
$subj = $x->subject;
- $subj = $srch->subject_normalized($subj);
+ $subj = subject_normalized($subj);
$subj = '(no subject)' if $subj eq '';
$ds = $x->ds;
if ($level == 0) {
@@ -1081,7 +1077,6 @@ sub dump_topics {
my @out;
my $ibx = $ctx->{-inbox};
my $obfs_ibx = $ibx->{obfuscate} ? $ibx : undef;
- my $srch = $ctx->{srch};
# sort by recency, this allows new posts to "bump" old topics...
foreach my $topic (sort { $b->[0] <=> $a->[0] } @$order) {
@@ -1113,7 +1108,7 @@ sub dump_topics {
my $level = $ex[$i];
my $subj = $ex[$i + 1];
$mid = delete $seen->{$subj};
- my @subj = split(/ /, $srch->subject_normalized($subj));
+ my @subj = split(/ /, subject_normalized($subj));
my @next_prev = @subj; # full copy
my $omit = dedupe_subject($prev_subj, \@subj, ' "');
$prev_subj = \@next_prev;
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index 1f3ca15..0f963dc 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -168,7 +168,6 @@ sub r404 {
my ($ctx) = @_;
if ($ctx && $ctx->{mid}) {
require PublicInbox::ExtMsg;
- searcher($ctx);
return PublicInbox::ExtMsg::ext_msg($ctx);
}
r(404, 'Not Found');
@@ -239,7 +238,6 @@ sub get_new {
sub get_index {
my ($ctx) = @_;
require PublicInbox::Feed;
- searcher($ctx);
if ($ctx->{env}->{QUERY_STRING} =~ /(?:\A|[&;])q=/) {
require PublicInbox::SearchView;
PublicInbox::SearchView::sres_top_html($ctx);
@@ -259,14 +257,13 @@ sub get_mid_txt {
sub get_mid_html {
my ($ctx) = @_;
require PublicInbox::View;
- searcher($ctx);
PublicInbox::View::msg_page($ctx) || r404($ctx);
}
# /$INBOX/$MESSAGE_ID/t/
sub get_thread {
my ($ctx, $flat) = @_;
- searcher($ctx) or return need_search($ctx);
+ $ctx->{-inbox}->over or return need($ctx, 'Overview');
$ctx->{flat} = $flat;
require PublicInbox::View;
PublicInbox::View::thread_html($ctx);
@@ -303,21 +300,11 @@ sub ctx_get {
$val;
}
-# search support is optional, returns undef if Xapian is not installed
-# or not configured for the given GIT_DIR
-sub searcher {
- my ($ctx) = @_;
- eval {
- require PublicInbox::Search;
- $ctx->{srch} = $ctx->{-inbox}->search;
- };
-}
-
-sub need_search {
- my ($ctx) = @_;
+sub need {
+ my ($ctx, $extra) = @_;
my $msg = <<EOF;
-<html><head><title>Search not available for this
-public-inbox</title><body><pre>Search is not available for this public-inbox
+<html><head><title>$extra not available for this
+public-inbox</title><body><pre>$extra is not available for this public-inbox
<a href="../">Return to index</a></pre></body></html>
EOF
[ 501, [ 'Content-Type' => 'text/html; charset=UTF-8' ], [ $msg ] ];
@@ -330,16 +317,16 @@ EOF
# especially on older systems. Stick to zlib since that's what git uses.
sub get_thread_mbox {
my ($ctx, $sfx) = @_;
- my $srch = searcher($ctx) or return need_search($ctx);
+ my $over = $ctx->{-inbox}->over or return need($ctx, 'Overview');
require PublicInbox::Mbox;
- PublicInbox::Mbox::thread_mbox($ctx, $srch, $sfx);
+ PublicInbox::Mbox::thread_mbox($ctx, $over, $sfx);
}
# /$INBOX/$MESSAGE_ID/t.atom -> thread as Atom feed
sub get_thread_atom {
my ($ctx) = @_;
- searcher($ctx) or return need_search($ctx);
+ $ctx->{-inbox}->over or return need($ctx, 'Overview');
require PublicInbox::Feed;
PublicInbox::Feed::generate_thread_atom($ctx);
}
@@ -453,7 +440,7 @@ sub serve_git {
sub mbox_results {
my ($ctx) = @_;
if ($ctx->{env}->{QUERY_STRING} =~ /(?:\A|[&;])q=/) {
- searcher($ctx) or return need_search($ctx);
+ $ctx->{-inbox}->search or return need($ctx, 'search');
require PublicInbox::SearchView;
return PublicInbox::SearchView::mbox_results($ctx);
}
@@ -464,7 +451,6 @@ sub serve_mbox_range {
my ($ctx, $inbox, $range) = @_;
invalid_inbox($ctx, $inbox) || eval {
require PublicInbox::Mbox;
- searcher($ctx);
PublicInbox::Mbox::emit_range($ctx, $range);
}
}
diff --git a/t/search.t b/t/search.t
index 35d7147..493e00d 100644
--- a/t/search.t
+++ b/t/search.t
@@ -223,7 +223,7 @@ $ibx->with_umask(sub {
$rw_commit->();
$ro->reopen;
- my $t = $ro->get_thread('root@s');
+ my $t = $ro->{over_ro}->get_thread('root@s');
is(scalar(@$t), 4, "got all 4 mesages in thread");
my @exp = sort($long_reply_mid, 'root@s', 'last@s', $long_mid);
@res = filter_mids($t);
@@ -422,7 +422,7 @@ $ibx->with_umask(sub {
if (scalar(@$n) >= 1) {
my $mid = $n->[0]->mid;
my ($id, $prev);
- $art = $ro->next_by_mid($mid, \$id, \$prev);
+ $art = $ro->{over_ro}->next_by_mid($mid, \$id, \$prev);
ok($art, 'article exists in OVER DB');
}
$rw->unindex_blob($amsg);
diff --git a/t/v2writable.t b/t/v2writable.t
index 5f34d12..b0f88d2 100644
--- a/t/v2writable.t
+++ b/t/v2writable.t
@@ -258,7 +258,7 @@ EOF
ok($im->add($mime), 'add excessively long References');
$im->barrier;
- my $msgs = $ibx->search->reopen->get_thread('x'x244);
+ my $msgs = $ibx->search->{over_ro}->get_thread('x'x244);
is(2, scalar(@$msgs), 'got both messages');
is($msgs->[0]->{mid}, 'x'x244, 'stored truncated mid');
is($msgs->[1]->{references}, '<'.('x'x244).'>', 'stored truncated ref');
diff --git a/t/view.t b/t/view.t
index ef7d695..0782954 100644
--- a/t/view.t
+++ b/t/view.t
@@ -13,6 +13,7 @@ my $ctx = {
env => { HTTP_HOST => 'example.com', 'psgi.url_scheme' => 'http' },
-inbox => Plack::Util::inline_object(
name => 'test',
+ over => sub { undef },
search => sub { undef },
base_url => sub { 'http://example.com/' },
cloneurl => sub {[]},
--
EW
next prev parent reply other threads:[~2019-05-15 6:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-15 6:33 [PATCH 0/6] make Search::Xapian optional for v2, NNTP, etc Eric Wong
2019-05-15 6:33 ` [PATCH 1/6] inbox: add ->over method to ease access Eric Wong
2019-05-15 6:33 ` [PATCH 2/6] nntp: use Inbox->over directly Eric Wong
2019-05-15 6:33 ` Eric Wong [this message]
2019-05-15 6:33 ` [PATCH 4/6] lazy load Xapian and make it optional for v2 Eric Wong
2019-05-15 6:33 ` [PATCH 5/6] searchidx: do not create empty Xapian partitions for basic Eric Wong
2019-05-15 6:33 ` [PATCH 6/6] admin: improve warnings and errors for missing modules Eric Wong
2019-05-22 0:35 ` [PATCH 0/6] make Search::Xapian optional for v2, NNTP, etc 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=20190515063354.52259-4-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).