Skip to content

Commit

Permalink
wip: move ES code out of controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
mickeyn committed Nov 23, 2016
1 parent bb62ce5 commit 57f3c8e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
20 changes: 20 additions & 0 deletions lib/MetaCPAN/Document/Release.pm
Expand Up @@ -365,6 +365,26 @@ sub find_github_based {
{ and => [ { term => { status => 'latest' } }, { or => $or } ] } );
}

sub latest_by_author {
my ( $self, $author ) = @_;

my $filter = {
and => [
{ term => { author => uc($author) } },
{ term => { status => 'latest' } }
]
};

my $file
= $self->filter($filter)
->sort(
[ 'distribution', { 'version_numified' => { reverse => 1 } } ] )
->fields( [qw< author distribution name status abstract date >] )
->size(1000)->all;

return $file;
}

sub top_uploaders {
my ( $self, $range ) = @_;

Expand Down
16 changes: 1 addition & 15 deletions lib/MetaCPAN/Server/Controller/Release.pm
Expand Up @@ -52,21 +52,7 @@ sub get : Path('') : Args(2) {

sub latest_by_author : Path('latest_by_author') : Args(1) {
my ( $self, $c, $author ) = @_;

my $filter = {
and => [
{ term => { author => uc($author) } },
{ term => { status => 'latest' } }
]
};

my $file
= $self->model($c)->raw->filter($filter)
->sort(
[ 'distribution', { 'version_numified' => { reverse => 1 } } ] )
->fields( [qw< author distribution name status abstract date >] )
->size(1000)->all;

my $file = $self->model($c)->raw->latest_by_author($author);
$c->stash($file);
}

Expand Down

0 comments on commit 57f3c8e

Please sign in to comment.