Skip to content

Commit

Permalink
Added /release/requires/MODULE endpoint
Browse files Browse the repository at this point in the history
This new endpoint is meant to replace current Elasticsearch
query crafted in WEB and passed to the the /release/_search
endpoint.
  • Loading branch information
mickeyn committed May 22, 2017
1 parent 9d83c7a commit 6d72647
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
44 changes: 44 additions & 0 deletions lib/MetaCPAN/Document/Release.pm
Expand Up @@ -539,5 +539,49 @@ sub get_files {
return { files => [ map { $_->{_source} } @{ $ret->{hits}{hits} } ] };
}

sub requires {
my ( $self, $module, $page, $page_size, $sort ) = @_;
$page //= 1;
$page_size //= 20;
$sort //= { date => 'desc' };

my $query = {
query => {
filtered => {
query => { 'match_all' => {} },
filter => {
and => [
{ term => { 'status' => 'latest' } },
{ term => { 'authorized' => 1 } },
{
term => {
'dependency.module' => $module
}
}
]
}
}
}
};

my $ret = $self->es->search(
index => $self->index->name,
type => 'release',
body => {
query => $query,
from => $page * $page_size - $page_size,
size => $page_size,
sort => [$sort],
}
);
return {} unless $ret->{hits}{total};

return +{
data => [ map { $_->{_source} } @{ $ret->{hits}{hits} } ],
total => $ret->{hits}{total},
took => $ret->{took}
};
}

__PACKAGE__->meta->make_immutable;
1;
8 changes: 8 additions & 0 deletions lib/MetaCPAN/Server/Controller/Release.pm
Expand Up @@ -67,5 +67,13 @@ sub files : Path('files') : Args(1) {
$c->stash($data);
}

sub requires : Path('requires') : Args(1) {
my ( $self, $c, $module ) = @_;
my @params = @{ $c->req->params }{qw< page page_size sort >};
my $data = $self->model($c)->raw->requires( $module, @params );
return unless $data;
$c->stash($data);
}

__PACKAGE__->meta->make_immutable;
1;

0 comments on commit 6d72647

Please sign in to comment.