Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #1891 from metacpan/mickey/use_requires_api
requires: use new API endpoint
  • Loading branch information
oalders committed May 25, 2017
2 parents 35e37e0 + 663bf0e commit 5d34c8e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 38 deletions.
4 changes: 1 addition & 3 deletions lib/MetaCPAN/Web/Controller/Requires.pm
Expand Up @@ -23,7 +23,6 @@ __PACKAGE__->config(
sub distribution : Local : Args(1) : Does('Sortable') {
my ( $self, $c, $distribution, $sort ) = @_;

my $cv = AE::cv();
my $page_size = $c->req->get_page_size(50);

my $data
Expand All @@ -44,12 +43,11 @@ sub distribution : Local : Args(1) : Does('Sortable') {
sub module : Local : Args(1) : Does('Sortable') {
my ( $self, $c, $module, $sort ) = @_;

my $cv = AE::cv();
my $page_size = $c->req->get_page_size(50);

my $data
= $c->model('API::Module')
->requires( $module, $c->req->page, $page_size, $sort )->recv;
->requires( $module, $c->req->page, $page_size, $sort );
$c->stash(
{
%{$data},
Expand Down
45 changes: 10 additions & 35 deletions lib/MetaCPAN/Web/Model/API/Module.pm
Expand Up @@ -79,42 +79,17 @@ sub first {

sub requires {
my ( $self, $module, $page, $page_size, $sort ) = @_;
$sort ||= { date => 'desc' };
my $cv = $self->cv;
$self->request(
'/release/_search',

my $data = $self->request(
"/release/requires/$module",
undef,
{
query => {
bool => {
must => [
{ term => { 'status' => 'latest' } },
{ term => { 'authorized' => 1 } },
{
term => {
'dependency.module' => $module
}
}
]
}
},
size => $page_size,
from => $page * $page_size - $page_size,
sort => [$sort],
}
)->cb(
sub {
my $data = shift->recv;
$cv->send(
{
data =>
[ map { $_->{_source} } @{ $data->{hits}->{hits} } ],
total => $data->{hits}->{total},
took => $data->{took}
}
);
}
);
return $cv;
page => $page,
page_size => $page_size,
},
)->recv;

return $data;
}

__PACKAGE__->meta->make_immutable;
Expand Down

0 comments on commit 5d34c8e

Please sign in to comment.