From 2cd663b34ebe0d505af228497cc882db540a35d5 Mon Sep 17 00:00:00 2001 From: Mickey Nasriachi Date: Tue, 4 Jul 2017 22:18:49 +0100 Subject: [PATCH 1/2] Use /release/latest_by_distribution API endpoint Replace query sending with using new API endpoint. --- lib/MetaCPAN/Web/Controller/Pod.pm | 3 +-- lib/MetaCPAN/Web/Controller/Release.pm | 10 ++++++---- lib/MetaCPAN/Web/Model/API/Release.pm | 20 +------------------- 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/lib/MetaCPAN/Web/Controller/Pod.pm b/lib/MetaCPAN/Web/Controller/Pod.pm index 6063d3d6c9..8c5357281e 100644 --- a/lib/MetaCPAN/Web/Controller/Pod.pm +++ b/lib/MetaCPAN/Web/Controller/Pod.pm @@ -58,8 +58,7 @@ sub distribution : Local : Args { # Get latest "author/release" of dist so we can use it to find the file. # TODO: Pass size param so we can disambiguate? my $release = try { - $c->model('API::Release')->find($dist)->get->{hits}{hits}->[0] - ->{_source}; + $c->model('API::Release')->find($dist)->get->{release}; } or $c->detach('/not_found'); # TODO: Disambiguate if there's more than once match. #176 diff --git a/lib/MetaCPAN/Web/Controller/Release.pm b/lib/MetaCPAN/Web/Controller/Release.pm index 824d507c3a..0c135e69e0 100644 --- a/lib/MetaCPAN/Web/Controller/Release.pm +++ b/lib/MetaCPAN/Web/Controller/Release.pm @@ -22,7 +22,7 @@ sub by_distribution : Chained('root') PathPart('') Args(1) { my ( $self, $c, $distribution ) = @_; my $model = $c->stash->{model}; - $c->stash->{data} = $model->find($distribution); + $c->stash->{data} = $model->find($distribution)->get->{release}; $c->forward('view'); } @@ -54,7 +54,10 @@ sub by_author_and_release : Chained('root') PathPart('') Args(2) { } $c->stash->{permalinks} = 1; - $c->stash->{data} = $model->get( $author, $release ); + my $data = $model->get( $author, $release )->get->{hits}->{hits}->[0] + ->{_source}; + $c->stash->{data} = $data; + $c->forward('view'); } @@ -62,8 +65,7 @@ sub view : Private { my ( $self, $c ) = @_; my $model = $c->stash->{model}; - my $data = delete $c->stash->{data}; - my $out = $data->get->{hits}->{hits}->[0]->{_source}; + my $out = delete $c->stash->{data}; $c->detach('/not_found') unless ($out); diff --git a/lib/MetaCPAN/Web/Model/API/Release.pm b/lib/MetaCPAN/Web/Model/API/Release.pm index 511e7cd155..ae6ce7e891 100644 --- a/lib/MetaCPAN/Web/Model/API/Release.pm +++ b/lib/MetaCPAN/Web/Model/API/Release.pm @@ -78,25 +78,7 @@ sub modules { sub find { my ( $self, $distribution ) = @_; - $self->request( - '/release/_search', - { - query => { - bool => { - must => [ - { - term => { - 'distribution' => $distribution - } - }, - { term => { status => 'latest' } } - ] - } - }, - sort => [ { date => 'desc' } ], - size => 1 - } - ); + $self->request("/release/latest_by_distribution/$distribution"); } # stolen from Module/requires From e1975234cd3f235254ccbed400e0ce4c2892dfdd Mon Sep 17 00:00:00 2001 From: Mickey Nasriachi Date: Tue, 4 Jul 2017 22:53:55 +0100 Subject: [PATCH 2/2] Use /release/by_author_and_name API endpoint Replace query sending with using new API endpoint. --- lib/MetaCPAN/Web/Controller/Pod.pm | 2 +- lib/MetaCPAN/Web/Controller/Release.pm | 9 ++++----- lib/MetaCPAN/Web/Model/API/Release.pm | 14 +------------- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/lib/MetaCPAN/Web/Controller/Pod.pm b/lib/MetaCPAN/Web/Controller/Pod.pm index 8c5357281e..a46ae70bb2 100644 --- a/lib/MetaCPAN/Web/Controller/Pod.pm +++ b/lib/MetaCPAN/Web/Controller/Pod.pm @@ -201,7 +201,7 @@ sub view : Private { }, ); - my $release = $reqs->{release}->{hits}->{hits}->[0]->{_source}; + my $release = $reqs->{release}{release}; #<<< my $canonical = ( $documented_module diff --git a/lib/MetaCPAN/Web/Controller/Release.pm b/lib/MetaCPAN/Web/Controller/Release.pm index 0c135e69e0..c2ac22e059 100644 --- a/lib/MetaCPAN/Web/Controller/Release.pm +++ b/lib/MetaCPAN/Web/Controller/Release.pm @@ -22,7 +22,7 @@ sub by_distribution : Chained('root') PathPart('') Args(1) { my ( $self, $c, $distribution ) = @_; my $model = $c->stash->{model}; - $c->stash->{data} = $model->find($distribution)->get->{release}; + $c->stash->{data} = $model->find($distribution); $c->forward('view'); } @@ -54,9 +54,7 @@ sub by_author_and_release : Chained('root') PathPart('') Args(2) { } $c->stash->{permalinks} = 1; - my $data = $model->get( $author, $release )->get->{hits}->{hits}->[0] - ->{_source}; - $c->stash->{data} = $data; + $c->stash->{data} = $model->get( $author, $release ); $c->forward('view'); } @@ -65,7 +63,8 @@ sub view : Private { my ( $self, $c ) = @_; my $model = $c->stash->{model}; - my $out = delete $c->stash->{data}; + my $data = delete $c->stash->{data}; + my $out = $data->get->{release}; $c->detach('/not_found') unless ($out); diff --git a/lib/MetaCPAN/Web/Model/API/Release.pm b/lib/MetaCPAN/Web/Model/API/Release.pm index ae6ce7e891..38f1d09588 100644 --- a/lib/MetaCPAN/Web/Model/API/Release.pm +++ b/lib/MetaCPAN/Web/Model/API/Release.pm @@ -27,19 +27,7 @@ it under the same terms as Perl itself. sub get { my ( $self, $author, $release ) = @_; - $self->request( - '/release/_search', - { - query => { - bool => { - must => [ - { term => { 'name' => $release } }, - { term => { author => uc($author) } } - ] - } - } - } - ); + $self->request("/release/by_author_and_name/$author/$release"); } sub distribution {