From 59e4f65298aaf2c1325211bf690c477a9096b5df Mon Sep 17 00:00:00 2001
From: Eelco Dolstra
Date: Tue, 9 Feb 2010 13:47:20 +0000
Subject: [PATCH] * Speed up the jobset index page. Especially the query to
get the inactive jobs was quite slow. * "IndexBy" -> "IndexOn".
---
src/lib/Hydra/Controller/Jobset.pm | 69 ++++++++++++++++++------------
src/root/jobset.tt | 6 +--
src/sql/hydra.sql | 28 ++++++------
3 files changed, 60 insertions(+), 43 deletions(-)
diff --git a/src/lib/Hydra/Controller/Jobset.pm b/src/lib/Hydra/Controller/Jobset.pm
index 053742ed..e66ceecd 100644
--- a/src/lib/Hydra/Controller/Jobset.pm
+++ b/src/lib/Hydra/Controller/Jobset.pm
@@ -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;
diff --git a/src/root/jobset.tt b/src/root/jobset.tt
index e9432f0f..5ed874f9 100644
--- a/src/root/jobset.tt
+++ b/src/root/jobset.tt
@@ -238,15 +238,15 @@
[% IF activeJobs.size == 0 %](none)[% 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 %]
-
+
This jobset used to contain the following [% inactiveJobs.size %] jobs:
[% IF inactiveJobs.size == 0 %](none)[% 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 %]
diff --git a/src/sql/hydra.sql b/src/sql/hydra.sql
index 9ccf1136..6a962076 100644
--- a/src/sql/hydra.sql
+++ b/src/sql/hydra.sql
@@ -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