Skip to content

Commit

Permalink
Merge pull request #1187 from metacpan/haarg/fix-fix-download_url-perl
Browse files Browse the repository at this point in the history
actually really fix download_url end point for perl releases
  • Loading branch information
oalders authored Apr 26, 2024
2 parents 091a5fe + 560f1e6 commit 6bf88ac
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions lib/MetaCPAN/Query/Release.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1058,10 +1058,13 @@ sub find_download_url {
bool => {
must => [
{ term => { $prefix . 'authorized' => 1 } },
{ term => { $prefix . 'indexed' => 1 } },
(
$module_filter ? { term => { $prefix . 'name' => $name } }
: { term => { 'release' => $name } },
$module_filter
? (
{ term => { $prefix . 'indexed' => 1 } },
{ term => { $prefix . 'name' => $name } }
)
: { term => { 'distribution' => $name } },
),
(
exists $version_filters->{must}
Expand Down Expand Up @@ -1143,7 +1146,16 @@ sub find_download_url {
query => $query,
size => 1,
sort => \@sort,
_source => [ 'release', 'download_url', 'date', 'status' ],
_source => [ qw(
checksum_md5
checksum_sha256
date
download_url
release
status
version
name
) ],
};

my $res = $self->es->search(
Expand All @@ -1158,7 +1170,8 @@ sub find_download_url {
my @checksums;

my $hit = $res->{hits}{hits}[0];
my $release = exists $hit->{_source} ? $hit->{_source}{release} : undef;
my $source = $hit->{_source};
my $release = $source->{release};

if ($release) {
my $checksums = $self->get_checksums($release);
Expand All @@ -1176,10 +1189,17 @@ sub find_download_url {
);
}

return +{
%{ $hit->{_source} },
%{ $hit->{inner_hits}{module}{hits}{hits}[0]{_source} }, @checksums,
};
my $source_name = delete $source->{name};
if ( !$module_filter ) {
$source->{release} = $source_name;
}

my $module
= $hit->{inner_hits}{module}
? $hit->{inner_hits}{module}{hits}{hits}[0]{_source}
: {};

return +{ %$source, %$module, @checksums, };
}

sub _version_filters {
Expand Down

0 comments on commit 6bf88ac

Please sign in to comment.