Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Controller/DownloadURL - move data handling to Document module
Keep the controller code concise and unaware of the data structure.
  • Loading branch information
mickeyn committed Jul 8, 2017
1 parent 98061f2 commit f381ae6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
13 changes: 11 additions & 2 deletions lib/MetaCPAN/Document/File/Set.pm
Expand Up @@ -278,9 +278,18 @@ sub find_download_url {
};
}

return $self->size(1)->query($query)
my $res
= $self->size(1)->query($query)
->source( [ 'download_url', 'date', 'status' ] )
->search_type('dfs_query_then_fetch')->sort( \@sort );
->search_type('dfs_query_then_fetch')->sort( \@sort )->raw->all;
return unless $res->{hits}{total};

my $hit = $res->{hits}{hits}[0];

return +{
%{ $hit->{_source} },
%{ $hit->{inner_hits}{module}{hits}{hits}[0]{_source} },
};
}

sub _version_filters {
Expand Down
17 changes: 4 additions & 13 deletions lib/MetaCPAN/Server/Controller/Search/DownloadURL.pm
Expand Up @@ -13,19 +13,10 @@ has '+type' => ( default => 'file' );

sub get : Local : Path('/download_url') : Args(1) {
my ( $self, $c, $module ) = @_;
my $args = $c->req->params;

my $model = $self->model($c);
my $res = $model->find_download_url( $module, $args )->raw->all;
my $hit = $res->{hits}{hits}[0]
or return $c->detach( '/not_found', [] );

$c->stash(
{
%{ $hit->{_source} },
%{ $hit->{inner_hits}{module}{hits}{hits}[0]{_source} }
}
);
my $data
= $self->model($c)->find_download_url( $module, $c->req->params );
return $c->detach( '/not_found', [] ) unless $data;
$c->stash($data);
}

1;

0 comments on commit f381ae6

Please sign in to comment.