Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions lib/MetaCPAN/Web/Controller/Recent.pm
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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