aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieu Othacehe <othacehe@gnu.org>2020-12-02 17:14:01 +0100
committerMathieu Othacehe <othacehe@gnu.org>2020-12-02 17:18:15 +0100
commite35eee6a80a3100aa42656b5f3a4721916e89b31 (patch)
tree3f078fbacbef1392d1d70774cfa97eb2d4dc5163
parentfd432b8e8f449d691773e96e7d90f44761e01aa3 (diff)
downloadcuirass-e35eee6a80a3100aa42656b5f3a4721916e89b31.tar
cuirass-e35eee6a80a3100aa42656b5f3a4721916e89b31.tar.gz
database: Rewrite db-get-builds-max and db-get-builds-min.
* src/cuirass/database.scm (db-get-builds-min, db-get-builds-max): Rewrite SQL queries without nesting.
-rw-r--r--src/cuirass/database.scm22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm
index 9b17c67..adc046f 100644
--- a/src/cuirass/database.scm
+++ b/src/cuirass/database.scm
@@ -1312,18 +1312,16 @@ AND (:system IS NULL
and STATUS."
(with-db-worker-thread db
(let ((rows (sqlite-exec db "
-SELECT stoptime, MIN(rowid) FROM
-(SELECT rowid, stoptime FROM Builds
+SELECT stoptime, rowid FROM Builds
WHERE evaluation=" eval "
-AND stoptime = (SELECT MIN(stoptime)
-FROM Builds
-WHERE evaluation = " eval "
AND (" status " IS NULL OR (" status " = 'pending'
AND Builds.status < 0)
OR (" status " = 'succeeded'
AND Builds.status = 0)
OR (" status " = 'failed'
- AND Builds.status > 0))))")))
+ AND Builds.status > 0))
+ORDER BY stoptime ASC, rowid ASC
+LIMIT 1")))
(and=> (expect-one-row rows) vector->list))))
(define (db-get-builds-max eval status)
@@ -1331,18 +1329,16 @@ AND (" status " IS NULL OR (" status " = 'pending'
and STATUS."
(with-db-worker-thread db
(let ((rows (sqlite-exec db "
-SELECT stoptime, MAX(rowid) FROM
-(SELECT rowid, stoptime FROM Builds
-WHERE evaluation=" eval " AND
-stoptime = (SELECT MAX(stoptime)
-FROM Builds
-WHERE evaluation = " eval "
+SELECT stoptime, rowid FROM Builds
+WHERE evaluation=" eval "
AND (" status " IS NULL OR (" status " = 'pending'
AND Builds.status < 0)
OR (" status " = 'succeeded'
AND Builds.status = 0)
OR (" status " = 'failed'
- AND Builds.status > 0))))")))
+ AND Builds.status > 0))
+ORDER BY stoptime DESC, rowid DESC
+LIMIT 1")))
(and=> (expect-one-row rows) vector->list))))
(define (db-get-evaluation-specification eval)