about summary refs log tree commit homepage
path: root/lib/PublicInbox/Mbox.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-12-05 10:11:37 +0000
committerEric Wong <e@80x24.org>2020-12-05 21:41:52 +0000
commit89990b0cfc8bbdabc8d650325d9e1bc585df8a0c (patch)
treece962a5a8d00ed83c3f6caa5c1e5e91ec1966aaf /lib/PublicInbox/Mbox.pm
parent8e0aef5068aa71e58d4a049491229f41e6bf19fb (diff)
downloadpublic-inbox-89990b0cfc8bbdabc8d650325d9e1bc585df8a0c.tar.gz
inbox: simplify ->search and callers
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.
Diffstat (limited to 'lib/PublicInbox/Mbox.pm')
-rw-r--r--lib/PublicInbox/Mbox.pm14
1 files changed, 10 insertions, 4 deletions
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;