From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/2] inbox: simplify ->search and callers
Date: Sat, 5 Dec 2020 10:11:37 +0000 [thread overview]
Message-ID: <20201205101138.11973-2-e@80x24.org> (raw)
In-Reply-To: <20201205101138.11973-1-e@80x24.org>
Stop leaking WWW/PSGI-specific logic into classes like
PublicInbox::Inbox, which is used universally.
We'll also decouple $ibx->over from $ibx->search and just deal
with duplicate the code inside ->over to reduce argument
complexity in ->search.
This is also a step in moving away from using {psgi.errors}
to ease code sharing between IMAP, NNTP, and command-line
interfaces. Perl's built-in `warn' and `local $SIG{__WARN__}'
provides all the flexibility we need to control warning output
and should be universally understood by Perl hackers who may
be unfamiliar with PSGI.
---
lib/PublicInbox/Inbox.pm | 20 ++++++++++----------
lib/PublicInbox/Mbox.pm | 14 ++++++++++----
2 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index 5a22e40d..58651687 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -191,30 +191,30 @@ sub mm {
};
}
-sub search ($;$$) {
- my ($self, $over_only, $ctx) = @_;
- my $srch = $self->{search} ||= eval {
+sub search {
+ my ($self) = @_;
+ my $srch = $self->{search} //= eval {
_cleanup_later($self);
require PublicInbox::Search;
PublicInbox::Search->new($self);
};
- ($over_only || eval { $srch->xdb }) ? $srch : do {
- $ctx and $ctx->{env}->{'psgi.errors'}->print(<<EOF);
-`$self->{name}' search went away unexpectedly
-EOF
- undef;
- };
+ (eval { $srch->xdb }) ? $srch : undef;
}
sub over {
$_[0]->{over} //= eval {
- my $srch = search($_[0], 1) or return;
+ my $srch = $_[0]->{search} //= eval {
+ _cleanup_later($_[0]);
+ require PublicInbox::Search;
+ PublicInbox::Search->new($_[0]);
+ };
my $over = PublicInbox::Over->new("$srch->{xpfx}/over.sqlite3");
$over->dbh; # may fail
$over;
};
}
+
sub try_cat {
my ($path) = @_;
my $rv = '';
diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm
index 47025891..22516998 100644
--- a/lib/PublicInbox/Mbox.pm
+++ b/lib/PublicInbox/Mbox.pm
@@ -203,16 +203,22 @@ sub mbox_all_ids {
PublicInbox::MboxGz::mbox_gz($ctx, \&all_ids_cb, 'all');
}
+sub gone ($$) {
+ my ($ctx, $what) = @_;
+ warn "W: `$ctx->{-inbox}->{inboxdir}' $what went away unexpectedly\n";
+ undef;
+}
+
sub results_cb {
my ($ctx) = @_;
- my $over = $ctx->{-inbox}->over or return;
+ my $over = $ctx->{-inbox}->over or return gone($ctx, 'over');
while (1) {
while (defined(my $num = shift(@{$ctx->{ids}}))) {
my $smsg = $over->get_art($num) or next;
return $smsg;
}
# refill result set
- my $srch = $ctx->{-inbox}->search(undef, $ctx) or return;
+ my $srch = $ctx->{-inbox}->search or return gone($ctx,'search');
my $mset = $srch->mset($ctx->{query}, $ctx->{qopts});
my $size = $mset->size or return;
$ctx->{qopts}->{offset} += $size;
@@ -223,7 +229,7 @@ sub results_cb {
sub results_thread_cb {
my ($ctx) = @_;
- my $over = $ctx->{-inbox}->over or return;
+ my $over = $ctx->{-inbox}->over or return gone($ctx, 'over');
while (1) {
while (defined(my $num = shift(@{$ctx->{xids}}))) {
my $smsg = $over->get_art($num) or next;
@@ -234,7 +240,7 @@ sub results_thread_cb {
next if $over->expand_thread($ctx);
# refill result set
- my $srch = $ctx->{-inbox}->search(undef, $ctx) or return;
+ my $srch = $ctx->{-inbox}->search or return gone($ctx,'search');
my $mset = $srch->mset($ctx->{query}, $ctx->{qopts});
my $size = $mset->size or return;
$ctx->{qopts}->{offset} += $size;
next prev parent reply other threads:[~2020-12-05 10:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-05 10:11 [PATCH 0/2] isearch: per-inbox search using ->ALL Eric Wong
2020-12-05 10:11 ` Eric Wong [this message]
2020-12-05 10:11 ` [PATCH 2/2] isearch: emulate per-inbox search with ->ALL Eric Wong
2020-12-05 11:10 ` [PATCH 3/2] imap: support isearch and reduce Xapian queries Eric Wong
2020-12-05 22:26 ` [PATCH 4/2] search: reinstate "uid:" internal search prefix Eric Wong
2020-12-10 0:41 ` One, All; Some? [was: isearch: per-inbox search using ->ALL] 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=20201205101138.11973-2-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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
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).