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;
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]';
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,
}
# 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}};
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 {
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 {
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') {
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
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';
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> ) .
$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;
}
$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;
{
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');
};
{
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();
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');
}
$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>");
}
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;
}
sub filter_mids {
- my ($res) = @_;
- sort(map { $_->mid } @{$res->{msgs}});
+ my ($msgs) = @_;
+ sort(map { $_->mid } @$msgs);
}
{
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");
}
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");
# 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
$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");
],
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");
}
}
{
- 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');
}
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");
}
$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");
}
}
$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;
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();
'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();
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');
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));
$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
{
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');
}
{
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);
}
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');
}