Skip to content

Commit

Permalink
Merge pull request #1929 from metacpan/mickey/use_release_recent_ep
Browse files Browse the repository at this point in the history
Use new /release/recent API endpoint
  • Loading branch information
oalders committed Jun 23, 2017
2 parents 8663dad + c0fc17c commit 231cc45
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 39 deletions.
7 changes: 1 addition & 6 deletions lib/MetaCPAN/Web/Controller/Recent.pm
@@ -1,9 +1,6 @@
package MetaCPAN::Web::Controller::Recent;
use Moose;

use Importer 'MetaCPAN::Web::Elasticsearch::Adapter' =>
qw/ single_valued_arrayref_to_scalar /;

BEGIN { extends 'MetaCPAN::Web::Controller' }

sub index : Path : Args(0) {
Expand All @@ -15,16 +12,14 @@ sub index : Path : Args(0) {
my ($data)
= $c->model('API::Release')
->recent( $req->page, $page_size, $req->params->{f} || 'l' )->get;
my $latest = [ map { $_->{fields} } @{ $data->{hits}->{hits} } ];
single_valued_arrayref_to_scalar($latest);

$c->add_surrogate_key( 'RECENT', 'DIST_UPDATES' );
$c->browser_max_age('1m');
$c->cdn_max_age('1y'); # DIST_UPDATES will purge it

$c->stash(
{
recent => $latest,
recent => $data->{releases},
took => $data->{took},
total => $data->{hits}->{total},
template => 'recent.html',
Expand Down
37 changes: 4 additions & 33 deletions lib/MetaCPAN/Web/Model/API/Release.pm
Expand Up @@ -60,41 +60,12 @@ sub all_by_author {

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 >] }
}
}
};
}
$self->request(
'/release/_search',
'/release/recent',
{
size => $page_size,
from => ( $page - 1 ) * $page_size,
query => $query,
fields => [qw(name author status abstract date distribution)],
sort => [ { 'date' => { order => 'desc' } } ]
page => $page,
page_size => $page_size,
type => $type,
}
);
}
Expand Down

0 comments on commit 231cc45

Please sign in to comment.