Skip to content

Commit

Permalink
Skip more empty queries, this time in search results
Browse files Browse the repository at this point in the history
  • Loading branch information
rwstauner committed Apr 21, 2015
1 parent 9910ec6 commit b911dbc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/MetaCPAN/Web/Model/API/Favorite.pm
Expand Up @@ -10,6 +10,14 @@ sub get {
my ( $self, $user, @distributions ) = @_;
@distributions = uniq @distributions;
my $cv = $self->cv;

# If there are no distributions this will build a query with an empty
# filter and ES will return a parser error... so just skip it.
if ( !@distributions ) {
$cv->send( {} );
return $cv;
}

$self->request(
'/favorite/_search',
{
Expand Down
14 changes: 14 additions & 0 deletions lib/MetaCPAN/Web/Model/API/Module.pm
Expand Up @@ -75,6 +75,13 @@ sub search_expanded {
from => $from
}
)->recv;

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

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

Expand Down Expand Up @@ -121,6 +128,13 @@ sub search_collapsed {
&& $data->{hits}->{total} > $hits + ( $run - 2 ) * $RESULTS_PER_RUN );

@distributions = splice( @distributions, $from, $page_size );

# Everything else will fail (slowly and quietly) without distributions.
if ( !@distributions ) {
$cv->send( {} );
return $cv;
}

my $ratings = $self->model('Rating')->get(@distributions);
my $favorites = $self->model('Favorite')->get( $user, @distributions );
my $results = $self->model('Module')
Expand Down
8 changes: 8 additions & 0 deletions lib/MetaCPAN/Web/Model/API/Rating.pm
Expand Up @@ -29,6 +29,14 @@ sub get {
my ( $self, @distributions ) = @_;
@distributions = uniq @distributions;
my $cv = $self->cv;

# If there are no distributions this will build a query with an empty
# filter and ES will return a parser error... so just skip it.
if ( !@distributions ) {
$cv->send( {} );
return $cv;
}

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

0 comments on commit b911dbc

Please sign in to comment.