Jobset.pm: Factor out build->eval mapping.

We now have a searchBuildsAndEvalsForJobset, which creates such a
mapping for us, so we don't need to duplicate code in jobs_tab and
channels_tab.

Also, we're going to use this for the overview of a particular channel
as well, so it makes sense to put it in CatalystUtils instead of
directly in Jobset.pm.

Instead of eval->jobs, it's now eval->builds, because it's really an
aggregate over the builds schema, rather than the job schema.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
This commit is contained in:
aszlig 2015-04-26 07:37:37 +02:00
parent 1fdc258de0
commit c9aadd8b7d
No known key found for this signature in database
GPG key ID: D0EBD0EC8C2DC961
4 changed files with 53 additions and 52 deletions

View file

@ -108,77 +108,39 @@ sub jobs_tab : Chained('jobsetChain') PathPart('jobs-tab') Args(0) {
$c->stash->{filter} = $c->request->params->{filter} // ""; $c->stash->{filter} = $c->request->params->{filter} // "";
my $filter = "%" . $c->stash->{filter} . "%"; my $filter = "%" . $c->stash->{filter} . "%";
my @evals = $c->stash->{jobset}->jobsetevals->search({ hasnewbuilds => 1}, { order_by => "id desc", rows => 20 }); my ($evals, $builds) = searchBuildsAndEvalsForJobset(
$c->stash->{jobset},
my $evals = {}; { job => { ilike => $filter }, ischannel => 0 },
my %jobs; 10000
my $nrBuilds = 0; );
foreach my $eval (@evals) {
my @builds = $eval->builds->search(
{ job => { ilike => $filter }, ischannel => 0 },
{ columns => ['id', 'job', 'finished', 'buildstatus'] });
foreach my $b (@builds) {
my $jobName = $b->get_column('job');
$evals->{$eval->id}->{timestamp} = $eval->timestamp;
$evals->{$eval->id}->{jobs}->{$jobName} =
{ id => $b->id, finished => $b->finished, buildstatus => $b->buildstatus };
$jobs{$jobName} = 1;
$nrBuilds++;
}
last if $nrBuilds >= 10000;
}
if ($c->request->params->{showInactive}) { if ($c->request->params->{showInactive}) {
$c->stash->{showInactive} = 1; $c->stash->{showInactive} = 1;
foreach my $job ($c->stash->{jobset}->jobs->search({ name => { ilike => $filter } })) { foreach my $job ($c->stash->{jobset}->jobs->search({ name => { ilike => $filter } })) {
next if defined $jobs{$job->name}; next if defined $builds->{$job->name};
$c->stash->{inactiveJobs}->{$job->name} = $jobs{$job->name} = 1; $c->stash->{inactiveJobs}->{$job->name} = $builds->{$job->name} = 1;
} }
} }
$c->stash->{evals} = $evals; $c->stash->{evals} = $evals;
my @jobs = sort (keys %jobs); my @jobs = sort (keys %$builds);
$c->stash->{nrJobs} = scalar @jobs; $c->stash->{nrJobs} = scalar @jobs;
splice @jobs, 250 if $c->stash->{filter} eq ""; splice @jobs, 250 if $c->stash->{filter} eq "";
$c->stash->{jobs} = [@jobs]; $c->stash->{jobs} = [@jobs];
} }
# XXX: Pretty much a rip-off of jobs-tab, make it DRY!
sub channels_tab : Chained('jobsetChain') PathPart('channels-tab') Args(0) { sub channels_tab : Chained('jobsetChain') PathPart('channels-tab') Args(0) {
my ($self, $c) = @_; my ($self, $c) = @_;
$c->stash->{template} = 'jobset-channels-tab.tt'; $c->stash->{template} = 'jobset-channels-tab.tt';
my @evals = $c->stash->{jobset}->jobsetevals->search( my ($evals, $builds) = searchBuildsAndEvalsForJobset(
{ hasnewbuilds => 1}, $c->stash->{jobset},
{ order_by => "id desc", rows => 20 } { ischannel => 1 }
); );
my $evals = {};
my %channels;
foreach my $eval (@evals) {
my @builds = $eval->builds->search(
{ ischannel => 1 },
{ columns => ['id', 'job', 'finished', 'buildstatus'] }
);
foreach my $b (@builds) {
my $jobName = $b->get_column('job');
$evals->{$eval->id}->{timestamp} = $eval->timestamp;
$evals->{$eval->id}->{channels}->{$jobName} = {
id => $b->id,
finished => $b->finished,
buildstatus => $b->buildstatus
};
$channels{$jobName} = 1;
}
}
$c->stash->{evals} = $evals; $c->stash->{evals} = $evals;
my @channels = sort (keys %channels); my @channels = sort (keys %$builds);
$c->stash->{channels} = [@channels]; $c->stash->{channels} = [@channels];
} }

View file

@ -10,6 +10,7 @@ use Hydra::Helper::Nix;
our @ISA = qw(Exporter); our @ISA = qw(Exporter);
our @EXPORT = qw( our @EXPORT = qw(
getBuild getPreviousBuild getNextBuild getPreviousSuccessfulBuild getBuild getPreviousBuild getNextBuild getPreviousSuccessfulBuild
searchBuildsAndEvalsForJobset
error notFound gone accessDenied error notFound gone accessDenied
forceLogin requireUser requireProjectOwner requireAdmin requirePost isAdmin isProjectOwner forceLogin requireUser requireProjectOwner requireAdmin requirePost isAdmin isProjectOwner
trim trim
@ -85,6 +86,44 @@ sub getPreviousSuccessfulBuild {
} }
sub searchBuildsAndEvalsForJobset {
my ($jobset, $condition, $maxBuilds) = @_;
my @evals = $jobset->jobsetevals->search(
{ hasnewbuilds => 1},
{ order_by => "id desc",
rows => 20
});
my $evals = {};
my %builds;
my $nrBuilds = 0;
foreach my $eval (@evals) {
my @allBuilds = $eval->builds->search(
$condition,
{ columns => ['id', 'job', 'finished', 'buildstatus'] }
);
foreach my $b (@allBuilds) {
my $jobName = $b->get_column('job');
$evals->{$eval->id}->{timestamp} = $eval->timestamp;
$evals->{$eval->id}->{builds}->{$jobName} = {
id => $b->id,
finished => $b->finished,
buildstatus => $b->buildstatus
};
$builds{$jobName} = 1;
$nrBuilds++;
}
last if $maxBuilds && $nrBuilds >= $maxBuilds;
}
return ($evals, \%builds);
}
sub error { sub error {
my ($c, $msg, $status) = @_; my ($c, $msg, $status) = @_;
$c->response->status($status) if defined $status; $c->response->status($status) if defined $status;

View file

@ -24,7 +24,7 @@
<tr> <tr>
<th><span>[% INCLUDE renderJobName project=project.name jobset=jobset.name job=chan %]</span></th> <th><span>[% INCLUDE renderJobName project=project.name jobset=jobset.name job=chan %]</span></th>
[% FOREACH eval IN evalIds %] [% FOREACH eval IN evalIds %]
<td>[% r = evals.$eval.channels.$chan; IF r.id %]<a href="[% c.uri_for('/build' r.id) %]">[% INCLUDE renderBuildStatusIcon size=16 build=r %]</a>[% END %]</td> <td>[% r = evals.$eval.builds.$chan; IF r.id %]<a href="[% c.uri_for('/build' r.id) %]">[% INCLUDE renderBuildStatusIcon size=16 build=r %]</a>[% END %]</td>
[% END %] [% END %]
</tr> </tr>
[% END %] [% END %]

View file

@ -59,7 +59,7 @@
<tr> <tr>
<th><span [% IF inactiveJobs.$j %]class="muted override-link"[% END %]>[% INCLUDE renderJobName project=project.name jobset=jobset.name job=j %]</span></th> <th><span [% IF inactiveJobs.$j %]class="muted override-link"[% END %]>[% INCLUDE renderJobName project=project.name jobset=jobset.name job=j %]</span></th>
[% FOREACH eval IN evalIds %] [% FOREACH eval IN evalIds %]
<td>[% r = evals.$eval.jobs.$j; IF r.id %]<a href="[% c.uri_for('/build' r.id) %]">[% INCLUDE renderBuildStatusIcon size=16 build=r %]</a>[% END %]</td> <td>[% r = evals.$eval.builds.$j; IF r.id %]<a href="[% c.uri_for('/build' r.id) %]">[% INCLUDE renderBuildStatusIcon size=16 build=r %]</a>[% END %]</td>
[% END %] [% END %]
</tr> </tr>
[% END %] [% END %]