Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Use new /release/versions/DIST API endpoint" #1911

Merged
merged 1 commit into from
Jun 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/MetaCPAN/Web/Controller/Feed.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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} }
]
);
}

Expand Down
3 changes: 0 additions & 3 deletions lib/MetaCPAN/Web/Controller/Pod.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions lib/MetaCPAN/Web/Controller/Release.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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?
Expand Down
12 changes: 10 additions & 2 deletions lib/MetaCPAN/Web/Model/API/Release.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions lib/MetaCPAN/Web/Role/ReleaseInfo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
Expand All @@ -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};

Expand Down
4 changes: 2 additions & 2 deletions t/controller/shared/release-info.t
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);

Expand Down
17 changes: 12 additions & 5 deletions t/model/release.t
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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' );

Expand Down Expand Up @@ -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' );

Expand Down