* Speed up the jobset index page. Especially the query to get the

inactive jobs was quite slow.
* "IndexBy" -> "IndexOn".
This commit is contained in:
Eelco Dolstra 2010-02-09 13:47:20 +00:00
parent 4abdf86bd4
commit 59e4f65298
3 changed files with 60 additions and 43 deletions

View file

@ -27,16 +27,30 @@ sub jobsetIndex {
#getBuildStats($c, scalar $c->stash->{jobset}->builds);
$c->stash->{activeJobs} = [
$c->stash->{jobset}->builds->search(
{isCurrent => 1},
{select => ["job"], order_by => ["job"], distinct => 1}
)];
$c->stash->{inactiveJobs} = [
$c->stash->{jobset}->builds->search(
{},
{select => ["job"], order_by => ["job"], group_by => ["job"], having => { 'sum(isCurrent)' => 0 }}
)];
my $projectName = $c->stash->{project}->name;
my $jobsetName = $c->stash->{jobset}->name;
# Get the active / inactive jobs in this jobset.
my @jobs = $c->stash->{jobset}->jobs->search(
{ },
{ select => [
"name",
\("exists (select 1 from builds where project = '$projectName' and jobset = '$jobsetName' and job = me.name and isCurrent = 1) as active")
]
, as => ["name", "active"]
, order_by => ["name"] });
$c->stash->{activeJobs} = [];
$c->stash->{inactiveJobs} = [];
foreach my $job (@jobs) {
print STDERR $job->get_column('active'), "\n";
if ($job->get_column('active')) {
push @{$c->stash->{activeJobs}}, $job->name;
} else {
push @{$c->stash->{inactiveJobs}}, $job->name;
}
}
$c->stash->{systems} = [$c->stash->{jobset}->builds->search({iscurrent => 1}, {select => ["system"], distinct => 1})];
# status per system
@ -46,23 +60,24 @@ sub jobsetIndex {
}
if($forceStatus || scalar(@{$c->stash->{activeJobs}}) <= 20) {
my @select = ();
my @as = ();
push(@select, "job"); push(@as, "job");
foreach my $system (@systems) {
push(@select, "(SELECT buildstatus FROM BuildResultInfo bri NATURAL JOIN Builds b WHERE b.id = (SELECT MAX(id) FROM Builds t WHERE t.project = me.project AND t.jobset = me.jobset AND t.job = me.job AND t.system = '$system'))");
push(@as, $system);
push(@select, "(SELECT b.id FROM BuildResultInfo bri NATURAL JOIN Builds b WHERE b.id = (SELECT MAX(id) FROM Builds t WHERE t.project = me.project AND t.jobset = me.jobset AND t.job = me.job AND t.system = '$system'))");
push(@as, $system."-build");
}
$c->stash->{activeJobsStatus} = [$c->model('DB')->resultset('ActiveJobsForJobset')
->search( {}
, { bind => [$c->stash->{project}->name, $c->stash->{jobset}->name]
, select => \@select
, as => \@as
, order_by => ["job"]
})];
}
my @select = ();
my @as = ();
push(@select, "job"); push(@as, "job");
foreach my $system (@systems) {
push(@select, "(SELECT buildstatus FROM BuildResultInfo bri NATURAL JOIN Builds b WHERE b.id = (SELECT MAX(id) FROM Builds t WHERE t.project = me.project AND t.jobset = me.jobset AND t.job = me.job AND t.system = '$system'))");
push(@as, $system);
push(@select, "(SELECT b.id FROM BuildResultInfo bri NATURAL JOIN Builds b WHERE b.id = (SELECT MAX(id) FROM Builds t WHERE t.project = me.project AND t.jobset = me.jobset AND t.job = me.job AND t.system = '$system'))");
push(@as, $system."-build");
}
$c->stash->{activeJobsStatus} =
[ $c->model('DB')->resultset('ActiveJobsForJobset')->search(
{},
{ bind => [$c->stash->{project}->name, $c->stash->{jobset}->name]
, select => \@select
, as => \@as
, order_by => ["job"]
})];
}
# last builds for jobset
my $tmp = $c->stash->{jobset}->builds;

View file

@ -238,15 +238,15 @@
<blockquote>
[% IF activeJobs.size == 0 %]<em>(none)</em>[% END %]
[% FOREACH j IN activeJobs %] [% INCLUDE renderJobName project=project.name jobset=jobset.name job=j.get_column('job') %] [% END %]
[% FOREACH j IN activeJobs %] [% INCLUDE renderJobName project=project.name jobset=jobset.name job=j %] [% END %]
</blockquote>
</p>
<p>This jobset used to contain the following [% inactiveJobs.size %] jobs:
<blockquote>
[% IF inactiveJobs.size == 0 %]<em>(none)</em>[% END %]
[% FOREACH j IN inactiveJobs %] [% INCLUDE renderJobName project=project.name jobset=jobset.name job=j.get_column('job') %] [% END %]
[% FOREACH j IN inactiveJobs %] [% INCLUDE renderJobName project=project.name jobset=jobset.name job=j %] [% END %]
</blockquote>
</p>

View file

@ -422,20 +422,22 @@ create table JobsetInputHashes (
-- Some indices.
create index IndexBuildInputsByBuild on BuildInputs(build);
create index IndexBuildInputsByDependency on BuildInputs(dependency);
create index IndexBuildsByTimestamp on Builds(timestamp);
create index IndexBuildsByIsCurrent on Builds(isCurrent);
create index IndexBuildsByFinished on Builds(finished);
create index IndexBuildsByProject on Builds(project);
create index IndexBuildsByJobset on Builds(project, jobset);
create index IndexBuildsByJob on Builds(project, jobset, job);
create index IndexBuildsByJobAndSystem on Builds(project, jobset, job, system);
create index IndexBuildInputsOnBuild on BuildInputs(build);
create index IndexBuildInputsOnDependency on BuildInputs(dependency);
create index IndexBuildProducstOnBuildAndType on BuildProducts(build, type);
create index IndexBuildProductsOnBuild on BuildProducts(build);
create index IndexBuildResultInfo on BuildResultInfo(id); -- primary key index, not created automatically by PostgreSQL
create index IndexBuildSchedulingInfoByBuild on BuildSchedulingInfo(id); -- idem
create index IndexBuildProductsByBuild on BuildProducts(build);
create index IndexBuildProducstByBuildAndType on BuildProducts(build, type);
create index IndexBuildStepsByBuild on BuildSteps(build);
create index IndexBuildSchedulingInfoOnBuild on BuildSchedulingInfo(id); -- idem
create index IndexBuildStepsOnBuild on BuildSteps(build);
create index IndexBuildsOnFinished on Builds(finished);
create index IndexBuildsOnIsCurrent on Builds(isCurrent);
create index IndexBuildsOnJob on Builds(project, jobset, job);
create index IndexBuildsOnJobAndIsCurrent on Builds(project, jobset, job, isCurrent);
create index IndexBuildsOnJobAndSystem on Builds(project, jobset, job, system);
create index IndexBuildsOnJobset on Builds(project, jobset);
create index IndexBuildsOnProject on Builds(project);
create index IndexBuildsOnTimestamp on Builds(timestamp);
create index IndexJobsetAltsOnJobset on JobsetInputAlts(project, jobset);
#ifdef SQLITE