]> Sergey Matveev's repositories - public-inbox.git/commitdiff
www: rework query responses to avoid COUNT in SQLite
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Mon, 2 Apr 2018 00:04:55 +0000 (00:04 +0000)
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Mon, 2 Apr 2018 00:05:42 +0000 (00:05 +0000)
In many cases, we do not care about the total number of
messages.  It's a rather expensive operation in SQLite
(Xapian only provides an estimate).

For LKML, this brings top-level /$INBOX/ loading time from
~375ms to around 60ms on my system.  Days ago, this operation
was taking 800-900ms(!) for me before introducing the SQLite
overview DB.

14 files changed:
lib/PublicInbox/Feed.pm
lib/PublicInbox/Mbox.pm
lib/PublicInbox/Over.pm
lib/PublicInbox/Search.pm
lib/PublicInbox/View.pm
t/altid.t
t/convert-compact.t
t/over.t
t/search-thr-index.t
t/search.t
t/v2-add-remove-add.t
t/v2mda.t
t/v2writable.t
t/watch_maildir_v2.t

index 2f59f8c2939b258d0c028c07a323cbb85380fcfb..ff20d7faaef792fd91ba39d7d9627804a81d794b 100644 (file)
@@ -27,14 +27,13 @@ sub generate {
 sub generate_thread_atom {
        my ($ctx) = @_;
        my $mid = $ctx->{mid};
-       my $res = $ctx->{srch}->get_thread($mid);
-       return _no_thread() unless $res->{total};
+       my $msgs = $ctx->{srch}->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;
-       my $msgs = $res->{msgs};
        PublicInbox::WwwAtomStream->response($ctx, 200, sub {
                while (my $smsg = shift @$msgs) {
                        $ibx->smsg_mime($smsg) and return $smsg;
@@ -114,10 +113,10 @@ sub recent_msgs {
                my $o = $qp ? $qp->{o} : 0;
                $o += 0;
                $o = 0 if $o < 0;
-               my $res = $ibx->recent({ limit => $max, offset => $o });
+               my $msgs = $ibx->recent({ limit => $max, offset => $o });
                my $next = $o + $max;
-               $ctx->{next_page} = "o=$next" if $res->{total} >= $next;
-               return $res->{msgs};
+               $ctx->{next_page} = "o=$next" if scalar(@$msgs) == $max;
+               return $msgs;
        }
 
        my $hex = '[a-f0-9]';
index 1b68f027157fc0d6b87f97724cdb0eece696fcea..05de6be1a678f75ac258b24233c9f52d8c7a585f 100644 (file)
@@ -217,12 +217,12 @@ sub set_filename ($$) {
 sub getline {
        my ($self) = @_;
        my $ctx = $self->{ctx} or return;
-       my $res;
        my $ibx = $ctx->{-inbox};
        my $gz = $self->{gz};
+       my $msgs = $self->{msgs};
        do {
                # work on existing result set
-               while (defined(my $smsg = shift @{$self->{msgs}})) {
+               while (defined(my $smsg = shift @$msgs)) {
                        my $msg = eval { $ibx->msg_by_smsg($smsg) } or next;
                        $msg = Email::Simple->new($msg);
                        $gz->write(PublicInbox::Mbox::msg_str($ctx, $msg,
@@ -247,11 +247,9 @@ sub getline {
                }
 
                # refill result set
-               $res = $self->{cb}->($self->{opts});
-               $self->{msgs} = $res->{msgs};
-               $res = scalar @{$self->{msgs}};
-               $self->{opts}->{offset} += $res;
-       } while ($res);
+               $msgs = $self->{msgs} = $self->{cb}->($self->{opts});
+               $self->{opts}->{offset} += scalar @$msgs;
+       } while (@$msgs);
        $gz->close;
        delete $self->{ctx};
        ${delete $self->{buf}};
index cf7a884997d23a5b4fe94bab61f7e8a8719ca9a5..c74072a26c063ea3c8acaebf1b06f9da34ba03a8 100644 (file)
@@ -88,10 +88,12 @@ LIMIT 1
 SELECT * $cond
 ORDER BY ts ASC
 
+       return $msgs unless wantarray;
+
        my $nr = $dbh->selectrow_array(<<"", undef, $tid, $sid);
 SELECT COUNT(num) $cond
 
-       { total => $nr, msgs => $msgs };
+       ($nr, $msgs);
 }
 
 sub recent {
@@ -100,10 +102,12 @@ sub recent {
 SELECT * FROM over WHERE num > 0
 ORDER BY ts DESC
 
+       return $msgs unless wantarray;
+
        my $nr = $self->{dbh}->selectrow_array(<<'');
 SELECT COUNT(num) FROM over WHERE num > 0
 
-       { total => $nr, msgs => $msgs };
+       ($nr, $msgs);
 }
 
 sub get_art {
index 91251246ccf4ddf20a94af806787aae89637d14a..84c0a22fec077cbafc75b0eaecdae791002ad5b4 100644 (file)
@@ -185,10 +185,16 @@ sub get_thread {
 
 sub retry_reopen {
        my ($self, $cb) = @_;
-       my $ret;
        for my $i (1..10) {
-               eval { $ret = $cb->() };
-               return $ret unless $@;
+               if (wantarray) {
+                       my @ret;
+                       eval { @ret = $cb->() };
+                       return @ret unless $@;
+               } else {
+                       my $ret;
+                       eval { $ret = $cb->() };
+                       return $ret unless $@;
+               }
                # Exception: The revision being read has been discarded -
                # you should call Xapian::Database::reopen()
                if (ref($@) eq 'Search::Xapian::DatabaseModifiedError') {
@@ -226,8 +232,9 @@ sub _enquire_once {
        my @msgs = map {
                PublicInbox::SearchMsg->load_doc($_->get_document);
        } $mset->items;
+       return \@msgs unless wantarray;
 
-       { total => $mset->get_matches_estimated, msgs => \@msgs }
+       ($mset->get_matches_estimated, \@msgs)
 }
 
 # read-write
index 8ac405f2b73cd78ce91b8e308738898694ac732b..cad90a7934e1632c2a5a42b95b22c9698831b024 100644 (file)
@@ -408,9 +408,7 @@ sub thread_html {
        my ($ctx) = @_;
        my $mid = $ctx->{mid};
        my $srch = $ctx->{srch};
-       my $sres = $srch->get_thread($mid);
-       my $msgs = $sres->{msgs};
-       my $nr = $sres->{total};
+       my ($nr, $msgs) = $srch->get_thread($mid);
        return missing_thread($ctx) if $nr == 0;
        my $skel = '<hr><pre>';
        $skel .= $nr == 1 ? 'only message in thread' : 'end of thread';
@@ -649,8 +647,7 @@ sub thread_skel {
        my ($dst, $ctx, $hdr, $tpfx) = @_;
        my $srch = $ctx->{srch};
        my $mid = mids($hdr)->[0];
-       my $sres = $srch->get_thread($mid);
-       my $nr = $sres->{total};
+       my ($nr, $msgs) = $srch->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>  ) .
@@ -680,12 +677,11 @@ sub thread_skel {
        $ctx->{prev_attr} = '';
        $ctx->{prev_level} = 0;
        $ctx->{dst} = $dst;
-       $sres = $sres->{msgs};
 
        # reduce hash lookups in skel_dump
        my $ibx = $ctx->{-inbox};
        $ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
-       walk_thread(thread_results($ctx, $sres), $ctx, *skel_dump);
+       walk_thread(thread_results($ctx, $msgs), $ctx, *skel_dump);
 
        $ctx->{parent_msg} = $parent;
 }
@@ -1066,11 +1062,10 @@ sub index_topics {
 
        $ctx->{order} = [];
        my $srch = $ctx->{srch};
-       my $sres = $ctx->{-inbox}->recent({offset => $off, limit => 200 });
-       $sres = $sres->{msgs};
-       my $nr = scalar @$sres;
+       my $msgs = $ctx->{-inbox}->recent({offset => $off, limit => 200 });
+       my $nr = scalar @$msgs;
        if ($nr) {
-               walk_thread(thread_results($ctx, $sres), $ctx, *acc_topic);
+               walk_thread(thread_results($ctx, $msgs), $ctx, *acc_topic);
        }
        $ctx->{-next_o} = $off + $nr;
        $ctx->{-cur_o} = $off;
index 0f3b86c12fee11f6780e5f0f378a15405450b909..d4f6152e302651e34825d2e65a6c6dde5da5eb6a 100644 (file)
--- a/t/altid.t
+++ b/t/altid.t
@@ -50,12 +50,11 @@ my $altid = [ "serial:gmane:file=$alt_file" ];
 
 {
        my $ro = PublicInbox::Search->new($git_dir, $altid);
-       my $res = $ro->query("gmane:1234");
-       is($res->{total}, 1, 'got one match');
-       is($res->{msgs}->[0]->mid, 'a@example.com');
+       my $msgs = $ro->query("gmane:1234");
+       is_deeply([map { $_->mid } @$msgs], ['a@example.com'], 'got one match');
 
-       $res = $ro->query("gmane:666");
-       is($res->{total}, 0, 'body did NOT match');
+       $msgs = $ro->query("gmane:666");
+       is_deeply([], $msgs, 'body did NOT match');
 };
 
 {
index 92a6a9c588fb83f8213e00bdf5c769ac1cdd5d72..e2ba40a5892adc19e2839b15781f170a5037c62b 100644 (file)
@@ -99,8 +99,8 @@ foreach (@xdir) {
        is($st[2] & 07777, -f _ ? 0444 : 0755,
                'sharedRepository respected after v2 compact');
 }
-my $res = $ibx->recent({limit => 1000});
-is($res->{msgs}->[0]->{mid}, 'a-mid@b', 'message exists in history');
-is(scalar @{$res->{msgs}}, 1, 'only one message in history');
+my $msgs = $ibx->recent({limit => 1000});
+is($msgs->[0]->{mid}, 'a-mid@b', 'message exists in history');
+is(scalar @$msgs, 1, 'only one message in history');
 
 done_testing();
index bfe331ede2cbc5c75db85c942aa4f087bf1ad9d6..2a7e8d1d8eee20b0959d61b81aa738bf3b1bfb71 100644 (file)
--- a/t/over.t
+++ b/t/over.t
@@ -40,7 +40,7 @@ my $ddd = compress('');
 foreach my $s ('', undef) {
        $over->add_over([0, 98, [ 'a' ], [], $s, $ddd]);
        $over->add_over([0, 99, [ 'b' ], [], $s, $ddd]);
-       my $msgs = [ map { $_->{num} } @{$over->get_thread('a')->{msgs}} ];
+       my $msgs = [ map { $_->{num} } @{$over->get_thread('a')} ];
        is_deeply([98], $msgs,
                'messages not linked by empty subject');
 }
@@ -48,13 +48,13 @@ foreach my $s ('', undef) {
 $over->add_over([0, 98, [ 'a' ], [], 's', $ddd]);
 $over->add_over([0, 99, [ 'b' ], [], 's', $ddd]);
 foreach my $mid (qw(a b)) {
-       my $msgs = [ map { $_->{num} } @{$over->get_thread('a')->{msgs}} ];
+       my $msgs = [ map { $_->{num} } @{$over->get_thread('a')} ];
        is_deeply([98, 99], $msgs, 'linked messages by subject');
 }
 $over->add_over([0, 98, [ 'a' ], [], 's', $ddd]);
 $over->add_over([0, 99, [ 'b' ], ['a'], 'diff', $ddd]);
 foreach my $mid (qw(a b)) {
-       my $msgs = [ map { $_->{num} } @{$over->get_thread($mid)->{msgs}} ];
+       my $msgs = [ map { $_->{num} } @{$over->get_thread($mid)} ];
        is_deeply([98, 99], $msgs, "linked messages by Message-ID: <$mid>");
 }
 
index 3ddef8090b1bf99d706ae40547900c02b5664811..2aa97bffcb89580c6a205eeeff695c612457fec4 100644 (file)
@@ -49,8 +49,8 @@ foreach (reverse split(/\n\n/, $data)) {
 
 my $prev;
 foreach my $mid (@mids) {
-       my $res = $rw->{over}->get_thread($mid);
-       is(3, $res->{total}, "got all messages from $mid");
+       my $msgs = $rw->{over}->get_thread($mid);
+       is(3, scalar(@$msgs), "got all messages from $mid");
 }
 
 $rw->commit_txn_lazy;
index 51adb9fbc5829689a6ce28d2d1e59ee32ac57ded..c9bef718e42f204b574230bb0028dcfc892eaf63 100644 (file)
@@ -82,8 +82,8 @@ my $rw_commit = sub {
 }
 
 sub filter_mids {
-       my ($res) = @_;
-       sort(map { $_->mid } @{$res->{msgs}});
+       my ($msgs) = @_;
+       sort(map { $_->mid } @$msgs);
 }
 
 {
@@ -106,12 +106,12 @@ sub filter_mids {
        is_deeply(\@res, \@exp, 'got expected results for s:"" match');
 
        $res = $ro->query('s:"Hello world"', {limit => 1});
-       is(scalar @{$res->{msgs}}, 1, "limit works");
-       my $first = $res->{msgs}->[0];
+       is(scalar @$res, 1, "limit works");
+       my $first = $res->[0];
 
        $res = $ro->query('s:"Hello world"', {offset => 1});
-       is(scalar @{$res->{msgs}}, 1, "offset works");
-       my $second = $res->{msgs}->[0];
+       is(scalar @$res, 1, "offset works");
+       my $second = $res->[0];
 
        isnt($first, $second, "offset returned different result from limit");
 }
@@ -147,7 +147,7 @@ sub filter_mids {
 
        my $ghost_id = $rw->add_message($was_ghost);
        is($ghost_id, int($ghost_id), "ghost_id is an integer: $ghost_id");
-       my $msgs = $rw->{over}->get_thread('ghost-message@s')->{msgs};
+       my $msgs = $rw->{over}->get_thread('ghost-message@s');
        is(scalar(@$msgs), 2, 'got both messages in ghost thread');
        foreach (qw(sid tid)) {
                is($msgs->[0]->{$_}, $msgs->[1]->{$_}, "{$_} match");
@@ -169,7 +169,7 @@ sub filter_mids {
 
        # body
        $res = $ro->query('goodbye');
-       is($res->{msgs}->[0]->mid, 'last@s', 'got goodbye message body');
+       is($res->[0]->mid, 'last@s', 'got goodbye message body');
 }
 
 # long message-id
@@ -215,7 +215,7 @@ sub filter_mids {
        $rw_commit->();
        $ro->reopen;
        my $t = $ro->get_thread('root@s');
-       is($t->{total}, 4, "got all 4 mesages in thread");
+       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);
        is_deeply(\@res, \@exp, "get_thread works");
@@ -244,13 +244,13 @@ sub filter_mids {
                ],
                body => "theatre\nfade\n"));
        my $res = $rw->query("theatre");
-       is($res->{total}, 2, "got both matches");
-       is($res->{msgs}->[0]->mid, 'nquote@a', "non-quoted scores higher");
-       is($res->{msgs}->[1]->mid, 'quote@a', "quoted result still returned");
+       is(scalar(@$res), 2, "got both matches");
+       is($res->[0]->mid, 'nquote@a', "non-quoted scores higher");
+       is($res->[1]->mid, 'quote@a', "quoted result still returned");
 
        $res = $rw->query("illusions");
-       is($res->{total}, 1, "got a match for quoted text");
-       is($res->{msgs}->[0]->mid, 'quote@a',
+       is(scalar(@$res), 1, "got a match for quoted text");
+       is($res->[0]->mid, 'quote@a',
                "quoted result returned if nothing else");
 }
 
@@ -293,34 +293,34 @@ sub filter_mids {
 }
 
 {
-       my $res = $ro->query('d:19931002..20101002');
-       ok(scalar @{$res->{msgs}} > 0, 'got results within range');
-       $res = $ro->query('d:20101003..');
-       is(scalar @{$res->{msgs}}, 0, 'nothing after 20101003');
-       $res = $ro->query('d:..19931001');
-       is(scalar @{$res->{msgs}}, 0, 'nothing before 19931001');
+       my $msgs = $ro->query('d:19931002..20101002');
+       ok(scalar(@$msgs) > 0, 'got results within range');
+       $msgs = $ro->query('d:20101003..');
+       is(scalar(@$msgs), 0, 'nothing after 20101003');
+       $msgs = $ro->query('d:..19931001');
+       is(scalar(@$msgs), 0, 'nothing before 19931001');
 }
 
 # names and addresses
 {
        my $res = $ro->query('t:list@example.com');
-       is(scalar @{$res->{msgs}}, 6, 'searched To: successfully');
-       foreach my $smsg (@{$res->{msgs}}) {
+       is(scalar @$res, 6, 'searched To: successfully');
+       foreach my $smsg (@$res) {
                like($smsg->to, qr/\blist\@example\.com\b/, 'to appears');
        }
 
        $res = $ro->query('tc:list@example.com');
-       is(scalar @{$res->{msgs}}, 6, 'searched To+Cc: successfully');
-       foreach my $smsg (@{$res->{msgs}}) {
+       is(scalar @$res, 6, 'searched To+Cc: successfully');
+       foreach my $smsg (@$res) {
                my $tocc = join("\n", $smsg->to, $smsg->cc);
                like($tocc, qr/\blist\@example\.com\b/, 'tocc appears');
        }
 
        foreach my $pfx ('tcf:', 'c:') {
                $res = $ro->query($pfx . 'foo@example.com');
-               is(scalar @{$res->{msgs}}, 1,
+               is(scalar @$res, 1,
                        "searched $pfx successfully for Cc:");
-               foreach my $smsg (@{$res->{msgs}}) {
+               foreach my $smsg (@$res) {
                        like($smsg->cc, qr/\bfoo\@example\.com\b/,
                                'cc appears');
                }
@@ -328,9 +328,9 @@ sub filter_mids {
 
        foreach my $pfx ('', 'tcf:', 'f:') {
                $res = $ro->query($pfx . 'Laggy');
-               is(scalar @{$res->{msgs}}, 1,
+               is(scalar(@$res), 1,
                        "searched $pfx successfully for From:");
-               foreach my $smsg (@{$res->{msgs}}) {
+               foreach my $smsg (@$res) {
                        like($smsg->from, qr/Laggy Sender/,
                                "From appears with $pfx");
                }
@@ -341,23 +341,23 @@ sub filter_mids {
        $rw_commit->();
        $ro->reopen;
        my $res = $ro->query('b:hello');
-       is(scalar @{$res->{msgs}}, 0, 'no match on body search only');
+       is(scalar(@$res), 0, 'no match on body search only');
        $res = $ro->query('bs:smith');
-       is(scalar @{$res->{msgs}}, 0,
+       is(scalar(@$res), 0,
                'no match on body+subject search for From');
 
        $res = $ro->query('q:theatre');
-       is(scalar @{$res->{msgs}}, 1, 'only one quoted body');
-       like($res->{msgs}->[0]->from, qr/\AQuoter/, 'got quoted body');
+       is(scalar(@$res), 1, 'only one quoted body');
+       like($res->[0]->from, qr/\AQuoter/, 'got quoted body');
 
        $res = $ro->query('nq:theatre');
-       is(scalar @{$res->{msgs}}, 1, 'only one non-quoted body');
-       like($res->{msgs}->[0]->from, qr/\ANon-Quoter/, 'got non-quoted body');
+       is(scalar @$res, 1, 'only one non-quoted body');
+       like($res->[0]->from, qr/\ANon-Quoter/, 'got non-quoted body');
 
        foreach my $pfx (qw(b: bs:)) {
                $res = $ro->query($pfx . 'theatre');
-               is(scalar @{$res->{msgs}}, 2, "searched both bodies for $pfx");
-               like($res->{msgs}->[0]->from, qr/\ANon-Quoter/,
+               is(scalar @$res, 2, "searched both bodies for $pfx");
+               like($res->[0]->from, qr/\ANon-Quoter/,
                        "non-quoter first for $pfx");
        }
 }
@@ -396,13 +396,13 @@ sub filter_mids {
        $rw_commit->();
        $ro->reopen;
        my $n = $ro->query('n:attached_fart.txt');
-       is(scalar @{$n->{msgs}}, 1, 'got result for n:');
+       is(scalar @$n, 1, 'got result for n:');
        my $res = $ro->query('part_deux.txt');
-       is(scalar @{$res->{msgs}}, 1, 'got result without n:');
-       is($n->{msgs}->[0]->mid, $res->{msgs}->[0]->mid,
+       is(scalar @$res, 1, 'got result without n:');
+       is($n->[0]->mid, $res->[0]->mid,
                'same result with and without');
        my $txt = $ro->query('"inside another"');
-       is($txt->{msgs}->[0]->mid, $res->{msgs}->[0]->mid,
+       is($txt->[0]->mid, $res->[0]->mid,
                'search inside text attachments works');
 }
 $rw->commit_txn_lazy;
index b6c58872d78d7fd1eb0a3fca9535e573d3e0ab95..c8d12d34b5903ee64e7b39975d3f1c6365db1a94 100644 (file)
@@ -35,8 +35,8 @@ ok($im->add($mime), 'message added');
 ok($im->remove($mime), 'message added');
 ok($im->add($mime), 'message added again');
 $im->done;
-my $res = $ibx->recent({limit => 1000});
-is($res->{msgs}->[0]->{mid}, 'a-mid@b', 'message exists in history');
-is(scalar @{$res->{msgs}}, 1, 'only one message in history');
+my $msgs = $ibx->recent({limit => 1000});
+is($msgs->[0]->{mid}, 'a-mid@b', 'message exists in history');
+is(scalar @$msgs, 1, 'only one message in history');
 
 done_testing();
index be27ca072746b131a77d0579fd3b13d9bcc29ee0..ca1bb09c8ce27abe9d26f051eb98826d50993b5e 100644 (file)
--- a/t/v2mda.t
+++ b/t/v2mda.t
@@ -52,8 +52,8 @@ ok(PublicInbox::Import::run_die(['public-inbox-mda'], undef, $rdr),
        'mda delivered a message');
 
 $ibx = PublicInbox::Inbox->new($ibx);
-my $res = $ibx->search->query('');
-my $saved = $ibx->smsg_mime($res->{msgs}->[0]);
+my $msgs = $ibx->search->query('');
+my $saved = $ibx->smsg_mime($msgs->[0]);
 is($saved->{mime}->as_string, $mime->as_string, 'injected message');
 
 done_testing();
index 7e29ef7660de98376346f1b25c1615351098733e..1e8e40426138bc286bdd7a48f7fe089013d69d79 100644 (file)
@@ -249,7 +249,7 @@ EOF
        ok($im->add($mime), 'add excessively long References');
        $im->barrier;
 
-       my $msgs = $ibx->search->reopen->get_thread('x'x244)->{msgs};
+       my $msgs = $ibx->search->reopen->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');
index 85130e3c0e432a99dd0b4fe60e7822f624723e7d..a76e413f1b58945513c433e1bb6e5a21da6639e0 100644 (file)
@@ -50,8 +50,8 @@ ok($ibx, 'found inbox by name');
 my $srch = $ibx->search;
 
 PublicInbox::WatchMaildir->new($config)->scan('full');
-my $res = $srch->reopen->query('');
-is($res->{total}, 1, 'got one revision');
+my ($total, undef) = $srch->reopen->query('');
+is($total, 1, 'got one revision');
 
 # my $git = PublicInbox::Git->new("$mainrepo/git/0.git");
 # my @list = $git->qx(qw(rev-list refs/heads/master));
@@ -70,7 +70,7 @@ my $write_spam = sub {
 $write_spam->();
 is(unlink(glob("$maildir/new/*")), 1, 'unlinked old spam');
 PublicInbox::WatchMaildir->new($config)->scan('full');
-is($srch->reopen->query('')->{total}, 0, 'deleted file');
+is(($srch->reopen->query(''))[0], 0, 'deleted file');
 
 # check with scrubbing
 {
@@ -80,16 +80,16 @@ the body of a message to majordomo\@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html\n);
        PublicInbox::Emergency->new($maildir)->prepare(\$msg);
        PublicInbox::WatchMaildir->new($config)->scan('full');
-       $res = $srch->reopen->query('');
-       is($res->{total}, 1, 'got one file back');
-       my $mref = $ibx->msg_by_smsg($res->{msgs}->[0]);
+       my ($nr, $msgs) = $srch->reopen->query('');
+       is($nr, 1, 'got one file back');
+       my $mref = $ibx->msg_by_smsg($msgs->[0]);
        like($$mref, qr/something\n\z/s, 'message scrubbed on import');
 
        is(unlink(glob("$maildir/new/*")), 1, 'unlinked spam');
        $write_spam->();
        PublicInbox::WatchMaildir->new($config)->scan('full');
-       $res = $srch->reopen->query('');
-       is($res->{total}, 0, 'inbox is empty again');
+       ($nr, $msgs) = $srch->reopen->query('');
+       is($nr, 0, 'inbox is empty again');
 }
 
 {
@@ -103,8 +103,8 @@ More majordomo info at  http://vger.kernel.org/majordomo-info.html\n);
                local $SIG{__WARN__} = sub {}; # quiet spam check warning
                PublicInbox::WatchMaildir->new($config)->scan('full');
        }
-       $res = $srch->reopen->query('');
-       is($res->{total}, 0, 'inbox is still empty');
+       ($nr, $msgs) = $srch->reopen->query('');
+       is($nr, 0, 'inbox is still empty');
        is(unlink(glob("$maildir/new/*")), 1);
 }
 
@@ -116,9 +116,9 @@ More majordomo info at  http://vger.kernel.org/majordomo-info.html\n);
        PublicInbox::Emergency->new($maildir)->prepare(\$msg);
        $config->{'publicinboxwatch.spamcheck'} = 'spamc';
        PublicInbox::WatchMaildir->new($config)->scan('full');
-       $res = $srch->reopen->query('');
-       is($res->{total}, 1, 'inbox has one mail after spamc OK-ed a message');
-       my $mref = $ibx->msg_by_smsg($res->{msgs}->[0]);
+       ($nr, $msgs) = $srch->reopen->query('');
+       is($nr, 1, 'inbox has one mail after spamc OK-ed a message');
+       my $mref = $ibx->msg_by_smsg($msgs->[0]);
        like($$mref, qr/something\n\z/s, 'message scrubbed on import');
 }