diff --git a/lib/MetaCPAN/Web/Controller/Feed.pm b/lib/MetaCPAN/Web/Controller/Feed.pm index a493ad99fc4..e5c6d6988f4 100644 --- a/lib/MetaCPAN/Web/Controller/Feed.pm +++ b/lib/MetaCPAN/Web/Controller/Feed.pm @@ -136,12 +136,14 @@ sub distribution : Local : Args(1) { $c->cdn_max_age('1y'); $c->add_dist_key($distribution); - my $versions = $c->model('API::Release')->versions($distribution); - + my $data = $c->model('API::Release')->versions($distribution)->recv; $c->stash->{feed} = $self->build_feed( host => $c->config->{web_host}, title => "Recent CPAN uploads of $distribution - MetaCPAN", - entries => $versions, + entries => [ + map { single_valued_arrayref_to_scalar($_) } + map { $_->{fields} } @{ $data->{hits}->{hits} } + ] ); } diff --git a/lib/MetaCPAN/Web/Controller/Pod.pm b/lib/MetaCPAN/Web/Controller/Pod.pm index bf23d05cfd0..ac2620a22a3 100644 --- a/lib/MetaCPAN/Web/Controller/Pod.pm +++ b/lib/MetaCPAN/Web/Controller/Pod.pm @@ -219,9 +219,6 @@ sub view : Private { my $dist = $release->{distribution}; - my $versions = $c->model('API::Release')->versions($dist); - $c->stash( { versions => $versions } ); - # Store at fastly for a year - as we will purge! $c->cdn_max_age('1y'); $c->add_dist_key($dist); diff --git a/lib/MetaCPAN/Web/Controller/Release.pm b/lib/MetaCPAN/Web/Controller/Release.pm index af24d5ba5c1..7e42bc70f45 100644 --- a/lib/MetaCPAN/Web/Controller/Release.pm +++ b/lib/MetaCPAN/Web/Controller/Release.pm @@ -133,14 +133,14 @@ sub view : Private { my $changes = $c->model('API::Changes')->last_version( $reqs->{changes}, $out ); - my $versions = $c->model('API::Release')->versions($distribution); - # TODO: make took more automatic (to include all) $c->stash( template => 'release.html', release => $out, total => $modules->{hits}->{total}, - took => List::Util::max( $modules->{took}, $files->{took} ), + took => List::Util::max( + $modules->{took}, $files->{took}, $reqs->{versions}->{took} + ), root => \@root_files, examples => \@examples, files => \@view_files, @@ -149,7 +149,6 @@ sub view : Private { documentation_raw => $categories->{documentation_raw}, provides => $categories->{provides}, modules => $categories->{modules}, - versions => $versions, # TODO: Put this in a more general place. # Maybe make a hash for feature flags? diff --git a/lib/MetaCPAN/Web/Model/API/Release.pm b/lib/MetaCPAN/Web/Model/API/Release.pm index ab11f22726b..9759e8a6a42 100644 --- a/lib/MetaCPAN/Web/Model/API/Release.pm +++ b/lib/MetaCPAN/Web/Model/API/Release.pm @@ -341,8 +341,16 @@ sub interesting_files { sub versions { my ( $self, $dist ) = @_; - my $data = $self->request("/release/versions/$dist")->recv; - return ( $data->{releases} || [] ); + $self->request( + '/release/_search', + { + query => { term => { distribution => $dist } }, + size => 250, + sort => [ { date => 'desc' } ], + fields => + [qw( name date author version status maturity authorized )], + } + ); } sub favorites { diff --git a/lib/MetaCPAN/Web/Role/ReleaseInfo.pm b/lib/MetaCPAN/Web/Role/ReleaseInfo.pm index 4318e3fb557..94074b96232 100644 --- a/lib/MetaCPAN/Web/Role/ReleaseInfo.pm +++ b/lib/MetaCPAN/Web/Role/ReleaseInfo.pm @@ -41,9 +41,10 @@ sub api_requests { rating => $c->model('API::Rating')->get( $data->{distribution} ), + versions => + $c->model('API::Release')->versions( $data->{distribution} ), distribution => $c->model('API::Release')->distribution( $data->{distribution} ), - %$reqs, }; } @@ -56,11 +57,13 @@ sub stash_api_results { author => $reqs->{author}, distribution => $reqs->{distribution}, rating => $reqs->{rating}->{ratings}->{ $data->{distribution} }, + versions => + [ map { $_->{fields} } @{ $reqs->{versions}->{hits}->{hits} } ], ); my %stash = map { $_ => single_valued_arrayref_to_scalar( $to_stash{$_} ) } - ( 'rating', 'distribution' ); + ( 'rating', 'distribution', 'versions' ); $stash{contributors} = $reqs->{contributors}; diff --git a/t/controller/shared/release-info.t b/t/controller/shared/release-info.t index 0219f427b6d..aa92897806b 100644 --- a/t/controller/shared/release-info.t +++ b/t/controller/shared/release-info.t @@ -114,9 +114,9 @@ test_psgi app, sub { # A fragile and unsure way to get the version, but at least an 80% solution. # TODO: Set up a fake cpan; We'll know what version to expect; we can test that this matches ok( - my ($version) = ( + my $version = ( $this =~ m!(?:/pod)?/release/[^/]+/\Q$release\E-([^/"]+)! - ), + )[0], 'got version from "this" link' ); diff --git a/t/model/release.t b/t/model/release.t index 2f8cbf8c90f..c1c0014ed73 100644 --- a/t/model/release.t +++ b/t/model/release.t @@ -8,6 +8,14 @@ use MetaCPAN::Web; use Importer 'MetaCPAN::Web::Elasticsearch::Adapter' => qw/ single_valued_arrayref_to_scalar /; +sub search_release { + my ( $method, @args ) = @_; + + return + map { @{ $_->{hits}{hits} } } + MetaCPAN::Web->model('API::Release')->$method(@args)->recv; +} + my ( $true, $false ) = @{ decode_json('[true, false]') }; # Explicitly test that we get a boolean. @@ -21,11 +29,9 @@ sub is_bool { } subtest modules => sub { - my @args = ( 'OALDERS', 'HTTP-CookieMonster-0.09' ); my @files = map { $_->{fields} } - @{ MetaCPAN::Web->model('API::Release')->modules(@args) - ->recv->{hits}{hits} }; + search_release( modules => 'OALDERS', 'HTTP-CookieMonster-0.09' ); ok( scalar @files, 'found files with modules' ); @@ -54,8 +60,9 @@ subtest modules => sub { subtest versions => sub { # Something with not too many versions. - my @versions = @{ MetaCPAN::Web->model('API::Release') - ->versions('Mojolicious-Plugin-HamlRenderer') }; + my @versions + = map { $_->{fields} } + search_release( versions => 'Mojolicious-Plugin-HamlRenderer' ); ok( scalar @versions, 'found release versions' );