Skip to content

Commit

Permalink
Merge pull request #1930 from metacpan/mickey/use_release_modules_end…
Browse files Browse the repository at this point in the history
…point

Use new /release/modules API endpoint
  • Loading branch information
oalders committed Jun 29, 2017
2 parents 9e985c3 + fe84348 commit 1da2e25
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 86 deletions.
16 changes: 9 additions & 7 deletions lib/MetaCPAN/Web/Controller/Release.pm
Expand Up @@ -118,10 +118,9 @@ sub view : Private {
$c->model('API::Favorite')->find_plussers($distribution)->get );

# Simplify the file data we pass to the template.
my @view_files = map +{ %{ $_->{fields} }, %{ $_->{_source} }, },
@{ $modules->{hits}->{hits} };
my $view_files = $modules->{files};

my $categories = $self->_files_to_categories( $out, \@view_files );
my $categories = $self->_files_to_categories( $out, $view_files );

my $changes
= $c->model('API::Changes')->last_version( $reqs->{changes}, $out );
Expand All @@ -130,13 +129,13 @@ sub view : Private {
$c->stash(
template => 'release.html',
release => $out,
total => $modules->{hits}->{total},
total => $modules->{total},
took => List::Util::max(
$modules->{took}, $files->{took}, $reqs->{versions}->{took}
),
root => \@root_files,
examples => \@examples,
files => \@view_files,
files => $view_files,

documentation => $categories->{documentation},
documentation_raw => $categories->{documentation_raw},
Expand Down Expand Up @@ -174,7 +173,9 @@ sub _files_to_categories {

for my $f (@$files) {
next if $f->{documentation};
for my $module ( @{ $f->{module} || [] } ) {
my @modules
= is_arrayref( $f->{module} ) ? @{ $f->{module} } : $f->{module};
for my $module ( grep {defined} @modules ) {
my $assoc = $module->{associated_pod} or next;
$assoc =~ s{^\Q$f->{author}/$f->{release}/}{};
if ( $assoc ne $f->{path}
Expand All @@ -200,7 +201,8 @@ sub _files_to_categories {
author => $f->{author},
);

my @modules = @{ $f->{module} || [] };
my @modules
= is_arrayref( $f->{module} ) ? @{ $f->{module} } : $f->{module};

if ( $f->{documentation} and @modules ) {
push @{ $ret->{modules} }, $f;
Expand Down
77 changes: 1 addition & 76 deletions lib/MetaCPAN/Web/Model/API/Release.pm
Expand Up @@ -73,82 +73,7 @@ sub recent {

sub modules {
my ( $self, $author, $release ) = @_;
$self->request(
'/file/_search',
{
query => {
bool => {
must => [
{ term => { release => $release } },
{ term => { author => $author } },
{ term => { directory => 0 } },
{
bool => {
should => [
{
bool => {
must => [
{
exists => {
field => 'module.name'
}
},
{
term => {
'module.indexed' => 1
}
}
]
}
},
{
bool => {
must => [
{
range => {
slop => { gt => 0 }
}
},
{
exists => {
field =>
'pod.analyzed'
}
},
{
term => { 'indexed' => 1 }
},
]
}
}
]
}
}
]
}
},
size => 999,

# Sort by documentation name; if there isn't one, sort by path.
sort => [ 'documentation', 'path' ],

_source => [ "module", "abstract" ],

fields => [
qw(
author
authorized
distribution
documentation
indexed
path
pod_lines
release
status
)
],
}
);
$self->request("/release/modules/$author/$release");
}

sub find {
Expand Down
5 changes: 2 additions & 3 deletions t/model/release.t
Expand Up @@ -29,9 +29,8 @@ sub is_bool {
}

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

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

Expand Down

0 comments on commit 1da2e25

Please sign in to comment.