Skip to content

Commit

Permalink
Only purge in latest script if making a change
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
haarg committed Feb 27, 2024
1 parent b1625ce commit caacca8
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions lib/MetaCPAN/Script/Latest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use Log::Contextual qw( :log );
use Moose;
use MooseX::Aliases;
use Parse::CPAN::Packages::Fast;
use CPAN::DistnameInfo;
use Regexp::Common qw(time);
use Time::Local qw( timelocal );
use MetaCPAN::Types::TypeTiny qw( Bool Str );
Expand Down Expand Up @@ -88,7 +89,6 @@ sub run {

my %upgrade;
my %downgrade;
my @modules_to_purge;
my %queued_distributions;

my $total = @filter;
Expand Down Expand Up @@ -141,11 +141,9 @@ sub run {
'Searching for ' . @$filter . ' of ' . $total . ' modules'
}
if @module_filters > 1;
my $scroll
= $self->index->type('file')->filter($query)
->source(
[qw< author date distribution module.name release status >] )
->size(100)->raw->scroll;
my $scroll = $self->index->type('file')->filter($query)->source( [ qw(
author date distribution download_url module.name release status
) ] )->size(100)->raw->scroll;

$found_total += $scroll->total;

Expand Down Expand Up @@ -202,11 +200,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;
}
}
}
Expand All @@ -217,12 +213,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' );
}

Expand All @@ -238,17 +238,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.
Expand Down

0 comments on commit caacca8

Please sign in to comment.