Skip to content

Commit

Permalink
use metacpan's version api rather than an Elasticsearch query (#166)
Browse files Browse the repository at this point in the history
While MetaCPAN allows using raw elasticsearch queries, they can be
fragile as the Elasticsearch version changes. When possible, it is
better to use a supported API.

The output with and without this change is identical, aside from the
time stamp.
  • Loading branch information
haarg authored Nov 11, 2024
1 parent 0d43d44 commit 7db9aa5
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions util/generate
Original file line number Diff line number Diff line change
Expand Up @@ -93,29 +93,16 @@ sub all_releases {
FETCH: {
sleep $tries * 10;
debug( "Try $tries for $distribution" );
my $response = HTTP::Tiny->new->post(
'http://fastapi.metacpan.org/v1/release/_search',
{
headers => { 'Content-Type' => 'application/json' },
content => JSON::encode_json(
{
size => 5000,
fields => [ qw(date version status main_module) ],
filter => {
term => { distribution => $distribution }
},
sort => ['date'],
}
)
}
my $response = HTTP::Tiny->new->get(
'http://fastapi.metacpan.org/v1/release/versions/'.$distribution
);

$content_json = eval { JSON::decode_json( $response->{content} ) };
last if $content_json;
redo FETCH unless $tries++ > 3;
}

my @results = map { $_->{fields} } @{ $content_json->{hits}->{hits} };
my @results = sort { $a->{date} cmp $b->{date} } @{ $content_json->{releases} };
return unless @results;

return @results;
Expand Down

0 comments on commit 7db9aa5

Please sign in to comment.