Skip to content

Commit

Permalink
Use new /file/dir/PATH API endpoint
Browse files Browse the repository at this point in the history
Replace the Elasticsearch query sending with a call to the new
API endpoint.
  • Loading branch information
mickeyn committed Jun 2, 2017
1 parent ed913b7 commit c6329e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 32 deletions.
11 changes: 3 additions & 8 deletions lib/MetaCPAN/Web/Controller/Source.pm
Expand Up @@ -40,17 +40,12 @@ sub index : Path : Args {
);
}
if ( $module->{directory} ) {
my $files = $c->model('API::File')->dir(@module)->recv;
my $files = $c->model('API::File')->dir(@module);
$c->res->last_modified( $module->{date} );
$c->stash(
{
template => 'browse.html',
files => [
map { single_valued_arrayref_to_scalar( $_->{fields} ) }
@{ $files->{hits}->{hits} }
],
total => $files->{hits}->{total},
took => $files->{took},
template => 'browse.html',
files => $files,
author => shift @module,
release => shift @module,
directory => \@module,
Expand Down
28 changes: 4 additions & 24 deletions lib/MetaCPAN/Web/Model/API/File.pm
Expand Up @@ -13,30 +13,10 @@ sub source {
}

sub dir {
my ( $self, $author, $release, @path ) = @_;
$self->request(
'/file/_search',
{
query => {
bool => {
must => [
{ term => { 'level' => scalar @path } },
{ term => { 'author' => $author } },
{ term => { 'release' => $release } },
{
prefix => {
'path' => join( q{/}, @path, q{} )
}
},
]
},
},
size => 999,
fields => [
qw(name stat.mtime path stat.size directory slop documentation mime)
],
}
);
my ( $self, @path ) = @_;
my $path = join '/', @path;
my $data = $self->request("/file/dir/$path")->recv;
return $data->{dir};
}

__PACKAGE__->meta->make_immutable;
Expand Down

0 comments on commit c6329e0

Please sign in to comment.