Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Toss dists no longer in ecosystem from db on build complete
  • Loading branch information
zoffixznet committed Nov 25, 2015
1 parent 603b213 commit 76486e8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
17 changes: 16 additions & 1 deletion lib/DbBuilder.pm
Expand Up @@ -98,7 +98,7 @@ sub run {
);
}

$self->_save_build_stats;
$self->_remove_old_dists( $build_id )->_save_build_stats;

if ( $self->_restart_app ) {
log info => 'Restarting app ' . $self->_app;
Expand Down Expand Up @@ -167,13 +167,28 @@ sub _metas {
return @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;

$self;
}

sub _save_build_stats {
my $self = shift;

$self->_model_build_stats->update(
last_updated => time(),
dists_num => scalar( $self->_model_dists->find->@* ),
);

$self;
}

1;
Expand Down
4 changes: 3 additions & 1 deletion lib/DbBuilder/Dist.pm
Expand Up @@ -67,11 +67,13 @@ sub _load_from_source {
for my $source ( $self->_sources ) {
next unless $url =~ $source->re;
log info => "Using $source to load $url";
return $source->new(
my $dist = $source->new(
meta_url => $url,
logos_dir => $self->_logos_dir,
dist_db => $self->_dist_db,
)->load;
$dist->{build_id} = $self->_build_id;
return $dist;
}
log error => "Could not find a source module that could handle dist URL "
. "[$url]\nHere are all the source modules currently available:\n"
Expand Down
9 changes: 6 additions & 3 deletions lib/ModulesPerl6/Model/Dists.pm
Expand Up @@ -59,13 +59,14 @@ sub add {
});

$db->resultset('Dist')->update_or_create({
travis => { status => $dist->{travis_status} },
travis => { status => $dist->{travis_status} },
author => { # use same field for both, for now. TODO:fetch realname
author_id => $dist->{author_id}, name => $dist->{author_id},
},
dist_build_id => { id => $dist->{build_id} },
map +( $_ => $dist->{$_} ),
qw/name url description stars issues kwalitee
date_updated date_added build_id/,
date_updated date_added/,
});
}

Expand Down Expand Up @@ -95,7 +96,9 @@ sub remove_old {
my ( $self, $build_id ) = @_;
length $build_id or croak 'Missing Build ID to keep';

$self->_find(0, { build_id => { '!=', $build_id } })->delete_all;
$self->_db->resultset('Dist')->search({
build_id => { '!=', $build_id }
})->delete_all;

$self;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ModulesPerl6/Model/Dists/Schema/Result/Dist.pm
Expand Up @@ -21,7 +21,7 @@ belongs_to travis
=> 'ModulesPerl6::Model::Dists::Schema::Result::TravisStatus'
=> { status => 'travis_status' };

belongs_to build_id
belongs_to dist_build_id
=> 'ModulesPerl6::Model::Dists::Schema::Result::BuildId'
=> { id => 'build_id' };

Expand Down

0 comments on commit 76486e8

Please sign in to comment.