Navigation Menu

Skip to content

Commit

Permalink
Added /release/recent API endpoint, removed /release/requires
Browse files Browse the repository at this point in the history
This will replace query sending from WEB.

This commit also removes /release/requires endpoint which was
already moved to the new ReverseDependencies controller.
  • Loading branch information
mickeyn committed Jun 22, 2017
1 parent b9a91e1 commit fe21902
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 6 deletions.
56 changes: 56 additions & 0 deletions lib/MetaCPAN/Document/Release.pm
Expand Up @@ -904,5 +904,61 @@ sub _get_depended_releases {
return [ map { $_->{_source} } @{ $depended->{hits}{hits} } ];
}

sub recent {
my ( $self, $page, $page_size, $type ) = @_;
my $query;

if ( $type eq 'n' ) {
$query = {
constant_score => {
filter => {
bool => {
must => [
{ term => { first => 1 } },
{ terms => { status => [qw< cpan latest >] } },
]
}
}
}
};
}
elsif ( $type eq 'a' ) {
$query = { match_all => {} };
}
else {
$query = {
constant_score => {
filter => {
terms => { status => [qw< cpan latest >] }
}
}
};
}

my $body = {
size => $page_size,
from => ( $page - 1 ) * $page_size,
query => $query,
fields => [qw(name author status abstract date distribution)],
sort => [ { 'date' => { order => 'desc' } } ]
};

my $ret = $self->es->search(
index => $self->index->name,
type => 'release',
body => $body,
);
return unless $ret->{hits}{total};

my $data = [ map { $_->{fields} } @{ $ret->{hits}{hits} } ];
single_valued_arrayref_to_scalar($data);

return {
releases => $data,
total => $ret->{hits}{total},
took => $ret->{took}
};
}

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

# TODO: remove after deployed in Controller::ReverseDependencies
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 );
sub recent : Path('recent') : Args(0) {
my ( $self, $c ) = @_;
my @params = @{ $c->req->params }{qw( page page_size type )};
my $data = $self->model($c)->raw->recent(@params);
return unless $data;
$c->stash($data);
}
Expand All @@ -85,7 +84,7 @@ sub latest_by_author : Path('latest_by_author') : Args(1) {

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

0 comments on commit fe21902

Please sign in to comment.