Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Removed needless calls to model settings (raw)
Removed calls to 'raw' (ESX::Model) for the new API endpoints
which don't use the model for querying.

Changed all 'inflate(0)' calls to 'raw' (does the same) for
consistency.

Moved 'raw' calls from controllers back to the document where
possible (some cases will be dealt with later).
  • Loading branch information
mickeyn committed Jul 12, 2017
1 parent 3f6ffa5 commit 173a434
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 46 deletions.
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Document/Release.pm
Expand Up @@ -325,7 +325,7 @@ sub find {
{ term => { status => 'latest' } }
]
}
)->sort( [ { date => 'desc' } ] )->first;
)->sort( [ { date => 'desc' } ] )->raw->first;
return unless $file;

my $data = $file->{_source}
Expand Down
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Script/Author.pm
Expand Up @@ -52,7 +52,7 @@ sub index_authors {

log_debug {"Getting last update dates"};
my $dates
= $type->inflate(0)->filter( { exists => { field => 'updated' } } )
= $type->raw->filter( { exists => { field => 'updated' } } )
->size(10000)->all;
$dates = {
map {
Expand Down
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Script/Release.pm
Expand Up @@ -160,7 +160,7 @@ sub run {
{ term => { author => $d->cpanid } },
]
}
)->inflate(0)->count;
)->raw->count;
if ($count) {
log_info {"Skipping $file"};
next;
Expand Down
4 changes: 2 additions & 2 deletions lib/MetaCPAN/Script/Watcher.pm
Expand Up @@ -145,7 +145,7 @@ sub skip {
{ term => { author => $author } },
]
}
)->inflate(0)->count;
)->raw->count;
}

sub index_release {
Expand Down Expand Up @@ -182,7 +182,7 @@ sub reindex_release {
{ term => { archive => $info->filename } },
]
}
)->inflate(0)->first;
)->raw->first;
return unless ($release);
log_info {"Moving $release->{_source}->{name} to BackPAN"};

Expand Down
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Server/Controller/Activity.pm
Expand Up @@ -11,7 +11,7 @@ with 'MetaCPAN::Server::Role::JSONP';

sub get : Path('') : Args(0) {
my ( $self, $c ) = @_;
my $data = $c->model('CPAN::Release')->raw->activity( $c->req->params );
my $data = $c->model('CPAN::Release')->activity( $c->req->params );
return unless $data;
$c->stash($data);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/MetaCPAN/Server/Controller/Author.pm
Expand Up @@ -65,7 +65,7 @@ sub get : Path('') : Args(1) {
sub qsearch : Path('search') : Args(0) {
my ( $self, $c ) = @_;
my ( $query, $from ) = @{ $c->req->params }{qw( q from )};
my $data = $self->model($c)->raw->search( $query, $from );
my $data = $self->model($c)->search( $query, $from );
$data or return;
$c->stash($data);
}
Expand All @@ -79,15 +79,15 @@ sub by_ids : Path('by_ids') : Args(0) {
? $body_data->{id}
: [ $c->req->param('id') ];
return unless $ids and @{$ids};
my $data = $self->model($c)->raw->by_ids($ids);
my $data = $self->model($c)->by_ids($ids);
$data or return;
$c->stash($data);
}

# /author/by_user/USER_ID
sub by_user : Path('by_user') : Args(1) {
my ( $self, $c, $user ) = @_;
my $data = $self->model($c)->raw->by_user($user);
my $data = $self->model($c)->by_user($user);
$data or return;
$c->stash($data);
}
Expand All @@ -97,7 +97,7 @@ sub by_users : Path('by_user') : Args(0) {
my ( $self, $c ) = @_;
my @users = $c->req->param('user');
return unless @users;
my $data = $self->model($c)->raw->by_user( \@users );
my $data = $self->model($c)->by_user( \@users );
$data or return;
$c->stash($data);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Server/Controller/Changes.pm
Expand Up @@ -107,7 +107,7 @@ sub get : Chained('index') : PathPart('') : Args(2) {

sub find : Chained('index') : PathPart('') : Args(1) {
my ( $self, $c, $name ) = @_;
my $release = eval { $c->model('CPAN::Release')->raw->find($name); }
my $release = eval { $c->model('CPAN::Release')->find($name); }
or $c->detach( '/not_found', [] );

$c->forward( 'get', [ @$release{qw( author name )} ] );
Expand Down
5 changes: 2 additions & 3 deletions lib/MetaCPAN/Server/Controller/Contributor.pm
Expand Up @@ -12,15 +12,14 @@ with 'MetaCPAN::Server::Role::JSONP';

sub get : Path('') : Args(2) {
my ( $self, $c, $author, $name ) = @_;
my $data
= $self->model($c)->raw->find_release_contributors( $author, $name );
my $data = $self->model($c)->find_release_contributors( $author, $name );
return unless $data;
$c->stash($data);
}

sub by_pauseid : Path('by_pauseid') : Args(1) {
my ( $self, $c, $pauseid ) = @_;
my $data = $self->model($c)->raw->find_author_contributions($pauseid);
my $data = $self->model($c)->find_author_contributions($pauseid);
return unless $data;
$c->stash($data);
}
Expand Down
8 changes: 3 additions & 5 deletions lib/MetaCPAN/Server/Controller/Diff.pm
Expand Up @@ -33,11 +33,9 @@ sub release : Chained('index') : PathPart('release') : Args(1) {

my ( $latest, $previous );
try {
$latest
= $c->model('CPAN::Release')->inflate(0)->find($name);
$latest = $c->model('CPAN::Release')->raw->find($name);
$previous
= $c->model('CPAN::Release')->inflate(0)->predecessor($name)
->{_source};
= $c->model('CPAN::Release')->raw->predecessor($name)->{_source};
}
catch {
$c->detach('/not_found');
Expand All @@ -58,7 +56,7 @@ sub file : Chained('index') : PathPart('file') : Args(2) {
= map { [ @$_{qw(author release path)} ] }
map {
my $file = $_;
try { $c->model('CPAN::File')->inflate(0)->get($file)->{_source}; }
try { $c->model('CPAN::File')->raw->get($file)->{_source}; }
or $c->detach('/not_found');
} ( $source, $target );

Expand Down
12 changes: 6 additions & 6 deletions lib/MetaCPAN/Server/Controller/Favorite.pm
Expand Up @@ -31,14 +31,14 @@ sub find : Path('') : Args(2) {
sub by_user : Path('by_user') : Args(1) {
my ( $self, $c, $user ) = @_;
my $size = $c->req->param('size') || 250;
my $data = $self->model($c)->raw->by_user( $user, $size );
my $data = $self->model($c)->by_user( $user, $size );
$data or return;
$c->stash($data);
}

sub users_by_distribution : Path('users_by_distribution') : Args(1) {
my ( $self, $c, $distribution ) = @_;
my $data = $self->model($c)->raw->users_by_distribution($distribution);
my $data = $self->model($c)->users_by_distribution($distribution);
$data or return;
$c->stash($data);
}
Expand All @@ -47,14 +47,14 @@ sub recent : Path('recent') : Args(0) {
my ( $self, $c ) = @_;
my $page = $c->req->param('page') || 1;
my $size = $c->req->param('size') || 100;
my $data = $self->model($c)->raw->recent( $page, $size );
my $data = $self->model($c)->recent( $page, $size );
$data or return;
$c->stash($data);
}

sub leaderboard : Path('leaderboard') : Args(0) {
my ( $self, $c ) = @_;
my $data = $self->model($c)->raw->leaderboard();
my $data = $self->model($c)->leaderboard();
$data or return;
$c->stash($data);
}
Expand All @@ -74,8 +74,8 @@ sub agg_by_distributions : Path('agg_by_distributions') : Args(0) {
? $body_data->{user}
: $c->req->param('user');

my $data = $self->model($c)
->raw->agg_by_distributions( $distributions, $user );
my $data
= $self->model($c)->agg_by_distributions( $distributions, $user );
$data or return;
$c->stash($data);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Server/Controller/Mirror.pm
Expand Up @@ -11,7 +11,7 @@ with 'MetaCPAN::Server::Role::JSONP';

sub search : Path('search') : Args(0) {
my ( $self, $c ) = @_;
my $data = $self->model($c)->raw->search( $c->req->param('q') );
my $data = $self->model($c)->search( $c->req->param('q') );
return unless $data;
$c->stash($data);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Server/Controller/Package.pm
Expand Up @@ -10,7 +10,7 @@ with 'MetaCPAN::Server::Role::JSONP';
# https://fastapi.metacpan.org/v1/package/modules/Moose
sub modules : Path('modules') : Args(1) {
my ( $self, $c, $dist ) = @_;
my $last = $c->model('CPAN::Release')->raw->find($dist);
my $last = $c->model('CPAN::Release')->find($dist);
return unless $last;
my $data
= $self->model($c)->get_modules( $dist, $last->{version} );
Expand Down
6 changes: 3 additions & 3 deletions lib/MetaCPAN/Server/Controller/Permission.pm
Expand Up @@ -9,14 +9,14 @@ with 'MetaCPAN::Server::Role::JSONP';

sub by_author : Path('by_author') : Args(1) {
my ( $self, $c, $pauseid ) = @_;
my $data = $self->model($c)->raw->by_author($pauseid);
my $data = $self->model($c)->by_author($pauseid);
return unless $data;
$c->stash($data);
}

sub by_module : Path('by_module') : Args(1) {
my ( $self, $c, $module ) = @_;
my $data = $self->model($c)->raw->by_modules($module);
my $data = $self->model($c)->by_modules($module);
return unless $data;
$c->stash($data);
}
Expand All @@ -28,7 +28,7 @@ sub by_modules : Path('by_module') : Args(0) {
? $c->req->body_data->{module}
: [ $c->req->param('module') ];
return unless $modules and @{$modules};
my $data = $self->model($c)->raw->by_modules($modules);
my $data = $self->model($c)->by_modules($modules);
return unless $data;
$c->stash($data);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Server/Controller/Rating.pm
Expand Up @@ -16,7 +16,7 @@ sub by_distributions : Path('by_distributions') : Args(0) {
? $c->req->body_data->{distribution}
: [ $c->req->param('distribution') ];
return unless $distributions and @{$distributions};
my $data = $self->model($c)->raw->by_distributions($distributions);
my $data = $self->model($c)->by_distributions($distributions);
return unless $data;
$c->stash($data);
}
Expand Down
24 changes: 12 additions & 12 deletions lib/MetaCPAN/Server/Controller/Release.pm
Expand Up @@ -21,7 +21,7 @@ __PACKAGE__->config(

sub find : Path('') : Args(1) {
my ( $self, $c, $name ) = @_;
my $file = $self->model($c)->raw->find($name);
my $file = $self->model($c)->find($name);
$c->detach( '/not_found', [] ) unless $file;
$c->stash($file);
}
Expand Down Expand Up @@ -49,7 +49,7 @@ sub get : Path('') : Args(2) {

sub contributors : Path('contributors') : Args(2) {
my ( $self, $c, $author, $release ) = @_;
my $data = $self->model($c)->raw->get_contributors( $author, $release );
my $data = $self->model($c)->get_contributors( $author, $release );
$c->stash($data);
}

Expand All @@ -58,73 +58,73 @@ sub files : Path('files') : Args(1) {
my $files = $c->req->params->{files};
return unless $files;
my @files = split /,/, $files;
my $data = $self->model($c)->raw->get_files( $name, \@files );
my $data = $self->model($c)->get_files( $name, \@files );
$c->stash($data);
}

sub modules : Path('modules') : Args(2) {
my ( $self, $c, $author, $name ) = @_;
my $data = $self->model($c)->raw->modules( $author, $name );
my $data = $self->model($c)->modules( $author, $name );
return unless $data;
$c->stash($data);
}

sub recent : Path('recent') : Args(0) {
my ( $self, $c ) = @_;
my @params = @{ $c->req->params }{qw( page page_size type )};
my $data = $self->model($c)->raw->recent(@params);
my $data = $self->model($c)->recent(@params);
return unless $data;
$c->stash($data);
}

sub by_author_and_name : Path('by_author_and_name') : Args(2) {
my ( $self, $c, $author, $name ) = @_;
my $data = $self->model($c)->raw->by_author_and_name( $author, $name );
my $data = $self->model($c)->by_author_and_name( $author, $name );
return unless $data;
$c->stash($data);
}

sub by_author : Path('by_author') : Args(1) {
my ( $self, $c, $pauseid ) = @_;
my $size = $c->req->param('size');
my $data = $self->model($c)->raw->by_author( $pauseid, $size );
my $data = $self->model($c)->by_author( $pauseid, $size );
return unless $data;
$c->stash($data);
}

sub latest_by_distribution : Path('latest_by_distribution') : Args(1) {
my ( $self, $c, $dist ) = @_;
my $data = $self->model($c)->raw->latest_by_distribution($dist);
my $data = $self->model($c)->latest_by_distribution($dist);
return unless $data;
$c->stash($data);
}

sub latest_by_author : Path('latest_by_author') : Args(1) {
my ( $self, $c, $pauseid ) = @_;
my $data = $self->model($c)->raw->latest_by_author($pauseid);
my $data = $self->model($c)->latest_by_author($pauseid);
return unless $data;
$c->stash($data);
}

sub all_by_author : Path('all_by_author') : Args(1) {
my ( $self, $c, $pauseid ) = @_;
my @params = @{ $c->req->params }{qw( page page_size )};
my $data = $self->model($c)->raw->all_by_author( $pauseid, @params );
my $data = $self->model($c)->all_by_author( $pauseid, @params );
return unless $data;
$c->stash($data);
}

sub versions : Path('versions') : Args(1) {
my ( $self, $c, $dist ) = @_;
my $data = $self->model($c)->raw->versions($dist);
my $data = $self->model($c)->versions($dist);
return unless $data;
$c->stash($data);
}

sub top_uploaders : Path('top_uploaders') : Args() {
my ( $self, $c ) = @_;
my $range = $c->req->param('range') || 'weekly';
my $data = $self->model($c)->raw->top_uploaders($range);
my $data = $self->model($c)->top_uploaders($range);
return unless $data;
$c->stash($data);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Server/Controller/ReverseDependencies.pm
Expand Up @@ -21,7 +21,7 @@ sub dist : Path('dist') : Args(1) {
sub module : Path('module') : Args(1) {
my ( $self, $c, $module ) = @_;
my @params = @{ $c->req->params }{qw< page page_size sort >};
my $data = $c->model('CPAN::Release')->raw->requires( $module, @params );
my $data = $c->model('CPAN::Release')->requires( $module, @params );
$c->detach('/not_found') unless $data;
$c->stash($data);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Server/Controller/User.pm
Expand Up @@ -70,7 +70,7 @@ sub profile : Local : ActionClass('REST') {
$self->status_not_found( $c, message => 'Profile doesn\'t exist' );
$c->detach;
}
my $profile = $c->model('CPAN::Author')->inflate(0)->get( $pause->key );
my $profile = $c->model('CPAN::Author')->raw->get( $pause->key );
$c->stash->{profile} = $profile->{_source};
}

Expand Down
2 changes: 1 addition & 1 deletion t/release/pm-PL.t
Expand Up @@ -35,7 +35,7 @@ is( $pm->module->[0]->version,
my $files
= $idx->type('file')
->filter( { term => { release => 'uncommon-sense-0.01' }, } )
->inflate(0)->size(20)->all->{hits}->{hits};
->raw->size(20)->all->{hits}->{hits};
$files = [ map { $_->{_source} } @$files ];

is_deeply(
Expand Down

0 comments on commit 173a434

Please sign in to comment.