Skip to content

Commit

Permalink
Merge pull request #1909 from metacpan/mickey/top_uploaders_endpoint
Browse files Browse the repository at this point in the history
Use new /release/top_uploaders API endpoint
  • Loading branch information
oalders authored Jun 8, 2017
2 parents 4f92929 + ba58179 commit 169b80a
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 169b80a

Please sign in to comment.