Skip to content

Commit

Permalink
Use /release/versions API endpoint
Browse files Browse the repository at this point in the history
This time without breaking it off the async api.
  • Loading branch information
mickeyn committed Jun 21, 2017
1 parent 866a70a commit 383bcb1
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 31 deletions.
6 changes: 2 additions & 4 deletions lib/MetaCPAN/Web/Controller/Feed.pm
Expand Up @@ -137,13 +137,11 @@ sub distribution : Local : Args(1) {
$c->add_dist_key($distribution);

my $data = $c->model('API::Release')->versions($distribution)->get;

$c->stash->{feed} = $self->build_feed(
host => $c->config->{web_host},
title => "Recent CPAN uploads of $distribution - MetaCPAN",
entries => [
map { single_valued_arrayref_to_scalar($_) }
map { $_->{fields} } @{ $data->{hits}->{hits} }
]
entries => $data->{releases},
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/MetaCPAN/Web/Controller/Release.pm
Expand Up @@ -139,7 +139,7 @@ sub view : Private {
release => $out,
total => $modules->{hits}->{total},
took => List::Util::max(
$modules->{took}, $files->{took}, $reqs->{versions}->{took}
$modules->{took}, $files->{took}, $reqs->{versions}{took}
),
root => \@root_files,
examples => \@examples,
Expand Down
11 changes: 1 addition & 10 deletions lib/MetaCPAN/Web/Model/API/Release.pm
Expand Up @@ -308,16 +308,7 @@ sub interesting_files {

sub versions {
my ( $self, $dist ) = @_;
$self->request(
'/release/_search',
{
query => { term => { distribution => $dist } },
size => 250,
sort => [ { date => 'desc' } ],
fields =>
[qw( name date author version status maturity authorized )],
}
);
$self->request("/release/versions/$dist");
}

sub topuploaders {
Expand Down
3 changes: 1 addition & 2 deletions lib/MetaCPAN/Web/Role/ReleaseInfo.pm
Expand Up @@ -67,8 +67,7 @@ sub stash_api_results {
author => $reqs->{author},
distribution => $reqs->{distribution},
rating => $reqs->{rating}->{ratings}->{ $data->{distribution} },
versions =>
[ map { $_->{fields} } @{ $reqs->{versions}->{hits}->{hits} } ],
versions => $reqs->{versions}{releases},
);

my %stash
Expand Down
40 changes: 40 additions & 0 deletions metacpan_web.conf.local
@@ -0,0 +1,40 @@
# rename this file to metacpan::web.yml and put a ':' after 'name' if
# you want to use YAML like in old versions of Catalyst
name MetaCPAN::Web
default_view HTML

# api_secure = https://fastapi.metacpan.org
# api_external_secure = https://fastapi.metacpan.org
api_secure = http://localhost:5000
api_external_secure = http://localhost:5000
source_host = https://st.aticpan.org
web_host = https://metacpan.org
consumer_key = metacpan.dev
cookie_secret = seekrit
consumer_secret = ClearAirTurbulence

mark_unauthorized_releases = 0

#site_alert_message = The sky is falling.

<view HTML>
INCLUDE_PATH root/
TAG_STYLE asp
PRE_PROCESS preprocess.html
WRAPPER wrapper.html
TEMPLATE_EXTENSION .html
ENCODING utf8
AUTO_FILTER html
STAT_TTL 1
COMPILE_PERL 2
COMPILE_DIR var/tmp/templates
</view>

<view Raw>
WRAPPER ""
</view>

<controller Account::Turing>
public_key 6LeH2MsSAAAAANwz3AA73Gw5OjCVjT6I51Ev-ior
</controller>

20 changes: 6 additions & 14 deletions t/model/release.t
Expand Up @@ -8,14 +8,6 @@ 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)->get;
}

my ( $true, $false ) = @{ decode_json('[true, false]') };

# Explicitly test that we get a boolean.
Expand All @@ -29,9 +21,10 @@ sub is_bool {
}

subtest modules => sub {
my @files
= map { $_->{fields} }
search_release( modules => 'OALDERS', 'HTTP-CookieMonster-0.09' );
my @files = map { $_->{fields} }
map { @{ $_->{hits}{hits} } }
MetaCPAN::Web->model('API::Release')
->modules( 'OALDERS', 'HTTP-CookieMonster-0.09' )->get;

ok( scalar @files, 'found files with modules' );

Expand Down Expand Up @@ -61,15 +54,14 @@ subtest versions => sub {

# Something with not too many versions.
my @versions
= map { $_->{fields} }
search_release( versions => 'Mojolicious-Plugin-HamlRenderer' );
= @{ MetaCPAN::Web->model('API::Release')
->versions('Mojolicious-Plugin-HamlRenderer')->get->{releases} };

ok( scalar @versions, 'found release versions' );

my %statuses;
my @dates;
foreach my $version (@versions) {
single_valued_arrayref_to_scalar($version);

# Ensure we get a boolean so that conditions work as expected.
is_bool( $version->{authorized}, q['authorized' is a boolean] );
Expand Down

0 comments on commit 383bcb1

Please sign in to comment.