]> xenbits.xensource.com Git - people/liuw/osstest.git/commitdiff
sg-report-host-history: Move query preparation into jobquery
authorIan Jackson <ian.jackson@eu.citrix.com>
Tue, 16 Jun 2015 13:54:44 +0000 (14:54 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Thu, 18 Jun 2015 15:31:04 +0000 (16:31 +0100)
To get the scope of database locking, and of the SET LOCAL workaround,
right, it is convenient to move these query preparations into the
jobquery function.

No functional change.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
sg-report-host-history

index c56ed71e8c016f308c79de32be94843898d25a05..f7a773d920448267a55a35bdce93f7c80913871e 100755 (executable)
@@ -102,40 +102,6 @@ $dbh_tests->do("SET LOCAL enable_seqscan=false");
 # of the runvars table, rather than walking backwards through the
 # flights until it has what we've told it is enough.
 
-my $runvarq = db_prepare(<<END);
-    SELECT flight, job, name, val
-      FROM runvars
-     WHERE $namecond
-       AND val = ?
-       AND $flightcond
-     ORDER BY flight DESC
-     LIMIT $limit * 2 + 100
-END
-
-my $endedq = db_prepare(<<END);
-    SELECT finished, testid, status AS laststepstatus
-      FROM steps
-     WHERE flight=? AND job=? AND finished IS NOT NULL
-     ORDER BY finished DESC
-     LIMIT 1
-END
-
-my $infoq = db_prepare(<<END);
-    SELECT blessing, branch, intended, status
-      FROM flights
-      JOIN jobs USING (flight)
-     WHERE flight=? AND job=?
-END
-
-my $allocdq = db_prepare(<<END);
-    SELECT testid, finished, status
-      FROM steps
-     WHERE flight=? AND job=?
-       AND (testid='hosts-allocate' OR step='ts-hosts-allocate')
-     ORDER BY finished ASC
-     LIMIT 1
-END
-
 sub jobquery ($$) {
     my ($q, $jr) = @_;
     $q->execute($jr->{flight}, $jr->{job});
@@ -167,6 +133,40 @@ sub reporthost ($) {
 
     print H "</tr>\n";
 
+    our $runvarq //= db_prepare(<<END);
+       SELECT flight, job, name, val
+         FROM runvars
+        WHERE $namecond
+          AND val = ?
+          AND $flightcond
+        ORDER BY flight DESC
+        LIMIT $limit * 2 + 100
+END
+
+    our $endedq //= db_prepare(<<END);
+       SELECT finished, testid, status AS laststepstatus
+         FROM steps
+        WHERE flight=? AND job=? AND finished IS NOT NULL
+        ORDER BY finished DESC
+        LIMIT 1
+END
+
+    our $infoq //= db_prepare(<<END);
+       SELECT blessing, branch, intended, status
+         FROM flights
+         JOIN jobs USING (flight)
+        WHERE flight=? AND job=?
+END
+
+    our $allocdq //= db_prepare(<<END);
+       SELECT testid, finished, status
+         FROM steps
+        WHERE flight=? AND job=?
+          AND (testid='hosts-allocate' OR step='ts-hosts-allocate')
+        ORDER BY finished ASC
+        LIMIT 1
+END
+
     my @rows;
     $runvarq->execute($hostname);