From f078e8de57f4905f4dc6e50aa4b071c05dbb70f0 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Tue, 27 Feb 2024 00:35:48 +0100 Subject: [PATCH] Only purge in latest script if making a change The previous attempt to only purge changed dists in the latest script tried to only mark for purging when marking for upgrade or downgrade. But the if conditions to mark for upgrade/downgrade is not all of the logic. There are later conditions to limit which dists will be upgraded. Move the code marking dists to purge until after this later filtering. --- lib/MetaCPAN/Script/Latest.pm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/MetaCPAN/Script/Latest.pm b/lib/MetaCPAN/Script/Latest.pm index 3e5a120b3..77ba0bd6a 100644 --- a/lib/MetaCPAN/Script/Latest.pm +++ b/lib/MetaCPAN/Script/Latest.pm @@ -88,7 +88,6 @@ sub run { my %upgrade; my %downgrade; - my @modules_to_purge; my %queued_distributions; my $total = @filter; @@ -202,11 +201,9 @@ sub run { ) ); $upgrade{ $file_data->{distribution} } = $file_data; - push @modules_to_purge, @modules; } elsif ( $file_data->{status} eq 'latest' ) { $downgrade{ $file_data->{release} } = $file_data; - push @modules_to_purge, @modules; } } } @@ -217,12 +214,16 @@ sub run { type => 'file' ); + my %to_purge; + while ( my ( $dist, $file_data ) = each %upgrade ) { # Don't reindex if already marked as latest. # This just means that it hasn't changed (query includes 'latest'). next if ( !$self->force and $file_data->{status} eq 'latest' ); + $to_purge{ $file_data->{download_url} } = 1; + $self->reindex( $bulk, $file_data, 'latest' ); } @@ -238,17 +239,16 @@ sub run { && $upgrade{ $file_data->{distribution} }->{release} eq $file_data->{release} ); + $to_purge{ $file_data->{download_url} } = 1; + $self->reindex( $bulk, $file_data, 'cpan' ); } $bulk->flush; $self->index->refresh; - # We just want the CPAN::DistnameInfo - my @module_to_purge_dists = map { $_->distribution } @modules_to_purge; - # Call Fastly to purge - $self->purge_cpan_distnameinfos( \@module_to_purge_dists ); - + $self->purge_cpan_distnameinfos( [ + map CPAN::DistnameInfo->new($_), keys %to_purge ] ); } # Update the status for the release and all the files.