about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiQuery.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-09-21 07:41:59 +0000
committerEric Wong <e@80x24.org>2021-09-21 19:18:36 +0000
commitc1cfe2c2ff17bca3cafb9dea4d7a7697eeab9683 (patch)
treedcad22ec6df905ca6f19f00744b33fa1356e8946 /lib/PublicInbox/LeiQuery.pm
parent21fd0da3bcfba4d3564d262f88d3fd7479b6d5ee (diff)
downloadpublic-inbox-c1cfe2c2ff17bca3cafb9dea4d7a7697eeab9683.tar.gz
Avoid slurping gigantic (e.g. 100000) result sets into a single
response if a giant limit is specified, and instead use 10000
as a window for the mset with a given offset.  We'll also warn
and hint towards about the --limit= switch when the estimated
result set is larger than the default limit.
Diffstat (limited to 'lib/PublicInbox/LeiQuery.pm')
-rw-r--r--lib/PublicInbox/LeiQuery.pm9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/PublicInbox/LeiQuery.pm b/lib/PublicInbox/LeiQuery.pm
index d5f132f1..cb5ac8fb 100644
--- a/lib/PublicInbox/LeiQuery.pm
+++ b/lib/PublicInbox/LeiQuery.pm
@@ -41,6 +41,12 @@ sub _start_query { # used by "lei q" and "lei up"
 
         # descending docid order is cheapest, MUA controls sorting order
         $self->{mset_opt}->{relevance} //= -2 if $l2m || $opt->{threads};
+
+        my $tot = $self->{mset_opt}->{total} //= $self->{opt}->{limit} // 10000;
+        $self->{mset_opt}->{limit} = $tot > 10000 ? 10000 : $tot;
+        $self->{mset_opt}->{offset} //= 0;
+        $self->{mset_opt}->{threads} //= $opt->{threads};
+
         if ($self->{net}) {
                 require PublicInbox::LeiAuth;
                 $self->{auth} = PublicInbox::LeiAuth->new
@@ -118,9 +124,8 @@ sub lei_q {
         my $lxs = lxs_prepare($self) or return;
         $self->ale->refresh_externals($lxs, $self);
         my $opt = $self->{opt};
-        my %mset_opt = map { $_ => $opt->{$_} } qw(threads limit offset);
+        my %mset_opt;
         $mset_opt{asc} = $opt->{'reverse'} ? 1 : 0;
-        $mset_opt{limit} //= 10000;
         if (defined(my $sort = $opt->{'sort'})) {
                 if ($sort eq 'relevance') {
                         $mset_opt{relevance} = 1;