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:
parent
1fdc258de0
commit
c9aadd8b7d
|
@ -108,77 +108,39 @@ sub jobs_tab : Chained('jobsetChain') PathPart('jobs-tab') Args(0) {
|
|||
$c->stash->{filter} = $c->request->params->{filter} // "";
|
||||
my $filter = "%" . $c->stash->{filter} . "%";
|
||||
|
||||
my @evals = $c->stash->{jobset}->jobsetevals->search({ hasnewbuilds => 1}, { order_by => "id desc", rows => 20 });
|
||||
|
||||
my $evals = {};
|
||||
my %jobs;
|
||||
my $nrBuilds = 0;
|
||||
|
||||
foreach my $eval (@evals) {
|
||||
my @builds = $eval->builds->search(
|
||||
my ($evals, $builds) = searchBuildsAndEvalsForJobset(
|
||||
$c->stash->{jobset},
|
||||
{ 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;
|
||||
}
|
||||
10000
|
||||
);
|
||||
|
||||
if ($c->request->params->{showInactive}) {
|
||||
$c->stash->{showInactive} = 1;
|
||||
foreach my $job ($c->stash->{jobset}->jobs->search({ name => { ilike => $filter } })) {
|
||||
next if defined $jobs{$job->name};
|
||||
$c->stash->{inactiveJobs}->{$job->name} = $jobs{$job->name} = 1;
|
||||
next if defined $builds->{$job->name};
|
||||
$c->stash->{inactiveJobs}->{$job->name} = $builds->{$job->name} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
$c->stash->{evals} = $evals;
|
||||
my @jobs = sort (keys %jobs);
|
||||
my @jobs = sort (keys %$builds);
|
||||
$c->stash->{nrJobs} = scalar @jobs;
|
||||
splice @jobs, 250 if $c->stash->{filter} eq "";
|
||||
$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) {
|
||||
my ($self, $c) = @_;
|
||||
$c->stash->{template} = 'jobset-channels-tab.tt';
|
||||
|
||||
my @evals = $c->stash->{jobset}->jobsetevals->search(
|
||||
{ hasnewbuilds => 1},
|
||||
{ order_by => "id desc", rows => 20 }
|
||||
my ($evals, $builds) = searchBuildsAndEvalsForJobset(
|
||||
$c->stash->{jobset},
|
||||
{ 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;
|
||||
my @channels = sort (keys %channels);
|
||||
my @channels = sort (keys %$builds);
|
||||
$c->stash->{channels} = [@channels];
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ use Hydra::Helper::Nix;
|
|||
our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw(
|
||||
getBuild getPreviousBuild getNextBuild getPreviousSuccessfulBuild
|
||||
searchBuildsAndEvalsForJobset
|
||||
error notFound gone accessDenied
|
||||
forceLogin requireUser requireProjectOwner requireAdmin requirePost isAdmin isProjectOwner
|
||||
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 {
|
||||
my ($c, $msg, $status) = @_;
|
||||
$c->response->status($status) if defined $status;
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
<tr>
|
||||
<th><span>[% INCLUDE renderJobName project=project.name jobset=jobset.name job=chan %]</span></th>
|
||||
[% 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 %]
|
||||
</tr>
|
||||
[% END %]
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
<tr>
|
||||
<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 %]
|
||||
<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 %]
|
||||
</tr>
|
||||
[% END %]
|
||||
|
|
Loading…
Reference in a new issue