Skip to content

Commit

Permalink
Use new /release/top_uploaders API endpoint
Browse files Browse the repository at this point in the history
Replace sending query with use of the new API endpoint.
  • Loading branch information
mickeyn committed Jun 6, 2017
1 parent 4f92929 commit ba58179
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 35 deletions.
14 changes: 8 additions & 6 deletions lib/MetaCPAN/Web/Controller/Recent/TopUploaders.pm
Expand Up @@ -25,22 +25,24 @@ sub all : Local : Args(0) {
sub topuploaders : Private {
my ( $self, $c, $range ) = @_;

my $data = $c->model('API::Release')->topuploaders($range)->recv;
my $counts = { map { $_->{key} => $_->{doc_count} }
@{ $data->{aggregations}{author}{entries}{buckets} } };
my $authors = $c->model('API::Author')->get( keys %$counts )->recv;
my $data = $c->model('API::Release')->topuploaders($range);

my $authors
= $c->model('API::Author')->get( keys %{ $data->{counts} } )->recv;

$c->stash(
{
authors => [
sort { $b->{releases} <=> $a->{releases} } map {
{
%{ $_->{_source} },
releases => $counts->{ $_->{_source}->{pauseid} }
releases =>
$data->{counts}{ $_->{_source}->{pauseid} }
}
} @{ $authors->{hits}{hits} }
],
took => $data->{took},
total => $data->{aggregations}{author}{total},
total => $data->{total},
template => 'recent/topuploaders.html',
range => $range,
}
Expand Down
33 changes: 4 additions & 29 deletions lib/MetaCPAN/Web/Model/API/Release.pm
Expand Up @@ -352,35 +352,10 @@ sub favorites {

sub topuploaders {
my ( $self, $range ) = @_;
my $range_filter = {
range => {
date => {
from => $range eq 'all' ? 0 : DateTime->now->subtract(
$range eq 'weekly' ? 'weeks'
: $range eq 'monthly' ? 'months'
: $range eq 'yearly' ? 'years'
: 'weeks' => 1
)->truncate( to => 'day' )->iso8601
},
}
};
$self->request(
'/release/_search',
{
query => { match_all => {} },
aggregations => {
author => {
aggregations => {
entries => {
terms => { field => 'author', size => 50 }
}
},
filter => $range_filter,
},
},
size => 0,
}
);
my $param = $range ? { range => $range } : ();
my $data
= $self->request( '/release/top_uploaders', undef, $param )->recv;
return $data;
}

sub no_latest {
Expand Down

0 comments on commit ba58179

Please sign in to comment.