From 8b88ce19c2daddb0a6381ee0ce134cd6af085bc6 Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <e.dolstra@tudelft.nl>
Date: Wed, 4 Apr 2012 17:29:03 +0200
Subject: [PATCH] Huuuge speedup in the Hydra evaluator

The check to see whether a build had been scheduled in a previous
evaluation took about 200 ms for the nixpkgs:trunk jobset.  Given
that it has more than 15000 builds, this added up to a lot.  Now
it takes 0.2 ms per build.
---
 src/lib/Hydra/Helper/AddBuilds.pm | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/lib/Hydra/Helper/AddBuilds.pm b/src/lib/Hydra/Helper/AddBuilds.pm
index 9af78b0e..39ed2412 100644
--- a/src/lib/Hydra/Helper/AddBuilds.pm
+++ b/src/lib/Hydra/Helper/AddBuilds.pm
@@ -837,7 +837,13 @@ sub checkBuild {
         # account.  For instance, do we want a new build to be
         # scheduled if the meta.maintainers field is changed?
         if (defined $prevEval) {
-            my ($prevBuild) = $prevEval->builds->search({ job => $job->name, outPath => $outPath }, { rows => 1, columns => ['id'] });
+            my ($prevBuild) = $prevEval->builds->search(
+		# The "project" and "jobset" constraints are
+		# semantically unnecessary (because they're implied by
+		# the eval), but they give a factor 1000 speedup on
+		# the Nixpkgs jobset with PostgreSQL.
+		{ project => $project->name, jobset => $jobset->name, job => $job->name, outPath => $outPath }, 
+		{ rows => 1, columns => ['id'] });
             if (defined $prevBuild) {
                 print STDERR "    already scheduled/built as build ", $prevBuild->id, "\n";
                 $buildIds->{$prevBuild->id} = 0;