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

actually really fix download_url end point for perl releases #1187

Merged
merged 1 commit into from
Apr 26, 2024
Merged
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
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}
: {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably always want to add a $module //= {} as we are going to dereference it later

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ES query that would produce {inner_hits}{module} requires a module with a matching name. If inner_hits exists, {inner_hits}{module}{hits}{hits}[0]{_source} will always exist.


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that $source can be undef

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, we have verified that there was a result in $hit. We are requesting specific _source fields. Even if none of those fields are available, _source will still exist unless Elasticsearch is entirely broken. $source can not be undef.

}

sub _version_filters {
Expand Down