Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #1792 from metacpan/tsibley/malformed-file-search
Short-circuit correctly in search_expanded
  • Loading branch information
oalders committed Nov 18, 2016
2 parents 7e1c3dc + 5e259db commit f0833fb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/MetaCPAN/Web/Model/API/Module.pm
Expand Up @@ -80,15 +80,15 @@ sub search_expanded {
}
)->recv;

my @distributions = uniq
map { $_->{fields}->{distribution} } @{ $data->{hits}->{hits} };

# Everything after this will fail (slowly and silently) without results.
if ( !$data->{hits}->{total} ) {
unless (@distributions) {
$cv->send( {} );
return $cv;
}

my @distributions = uniq
map { $_->{fields}->{distribution} } @{ $data->{hits}->{hits} };

my @ids = map { $_->{fields}->{id} } @{ $data->{hits}->{hits} };
my $descriptions = $self->search_descriptions(@ids);
my $ratings = $self->model('Rating')->get(@distributions);
Expand Down Expand Up @@ -167,6 +167,12 @@ sub search_collapsed {
sub search_descriptions {
my ( $self, @ids ) = @_;
my $cv = $self->cv;

unless (@ids) {
$cv->send( {} );
return $cv;
}

$self->request(
'/file/_search',
{
Expand Down

0 comments on commit f0833fb

Please sign in to comment.