Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor: get deleted dists num prior to dumping them instead of fetc…
…hing all rows twice in db builder
  • Loading branch information
zoffixznet committed Nov 25, 2015
1 parent 76486e8 commit 727a71e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
9 changes: 3 additions & 6 deletions lib/DbBuilder.pm
Expand Up @@ -170,12 +170,9 @@ sub _metas {
sub _remove_old_dists {
my ( $self, $build_id ) = @_;

my $before = $self->_model_dists->find->@*;
$self->_model_dists->remove_old( $build_id );
my $after = $self->_model_dists->find->@*;
log info => 'Removed ' . ( $before - $after )
. ' dists that are no longer in the ecosystem'
if ($before - $after) != 0;
my $delta = $self->_model_dists->remove_old( $build_id );
log info => "Removed $delta dists that are no longer in the ecosystem"
if $delta;

$self;
}
Expand Down
8 changes: 5 additions & 3 deletions lib/ModulesPerl6/Model/Dists.pm
Expand Up @@ -96,11 +96,13 @@ sub remove_old {
my ( $self, $build_id ) = @_;
length $build_id or croak 'Missing Build ID to keep';

$self->_db->resultset('Dist')->search({
my $res = $self->_db->resultset('Dist')->search({
build_id => { '!=', $build_id }
})->delete_all;
});
my $num_deleted = $res->all;
$res->delete_all;

$self;
$num_deleted;
}

1;
Expand Down

0 comments on commit 727a71e

Please sign in to comment.