Skip to content

Commit

Permalink
[WIP] author: top_uploaders: move ES query to new API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyn committed Nov 20, 2016
1 parent fac9b8b commit 02e94cc
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions lib/MetaCPAN/Server/Controller/Author.pm
Expand Up @@ -114,4 +114,46 @@ sub by_user : Path('by_user') : Args(0) {
$self->es_by_key_vals( c => $c, key => 'user', vals => \@users );
}

# endpoint: /author/top_uploaders?range=<range>[&fields=<csv_fields>][&sort=<csv_sort>][&size=N]
sub top_uploaders : Path('top_uploaders') : Args(0) {
my ( $self, $c ) = @_;
my $range = $c->req->parameters->{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
},
}
};

my $body = +{
query => { match_all => {} },
aggregations => {
author => {
aggregations => {
entries => {
terms => { field => 'author', size => 50 }
}
},
filter => $range_filter,
},
},
size => 0,
};

my $res = $c->model('CPAN::Release')->es->search({
index => $c->model('CPAN::Release')->index->name,
type => 'release',
body => $body,
});

# TODO
}

1;

0 comments on commit 02e94cc

Please sign in to comment.