aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2018-04-05 22:15:20 +0200
committerLudovic Courtès <ludo@gnu.org>2018-04-05 22:15:20 +0200
commitfc24ca2eac708695f663623a50f715db5ca914bd (patch)
treeaca7bf9665e27c618884f6b06b721e0875c2882e /src
parent2feb3b8100d7a6e1db042ef24e9f2a897c953346 (diff)
downloadcuirass-fc24ca2eac708695f663623a50f715db5ca914bd.tar
cuirass-fc24ca2eac708695f663623a50f715db5ca914bd.tar.gz
database: Add 'db-get-pending-derivations'.
* src/cuirass/database.scm (db-get-pending-derivations): New procedure. * tests/database.scm ("database")["db-get-pending-derivations"]: New test.
Diffstat (limited to 'src')
-rw-r--r--src/cuirass/database.scm17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm
index b445719..4dda862 100644
--- a/src/cuirass/database.scm
+++ b/src/cuirass/database.scm
@@ -39,6 +39,7 @@
db-add-evaluation
db-add-derivation
db-get-derivation
+ db-get-pending-derivations
build-status
db-add-build
db-update-build-status!
@@ -508,6 +509,22 @@ ORDER BY ~a, Builds.id ASC LIMIT :nr;" order))
build)
(() #f)))
+(define (db-get-pending-derivations db)
+ "Return the list of derivation file names corresponding to pending builds in
+DB. The returned list is guaranteed to not have any duplicates."
+ ;; This is of course much more efficient than calling 'delete-duplicates' on
+ ;; a list of results obtained without DISTINCT, both in space and time.
+ ;;
+ ;; Here we use a subquery so that sqlite can use two indexes instead of
+ ;; creating a "TEMP B-TREE" when doing a single flat query, as "EXPLAIN
+ ;; QUERY PLAN" shows.
+ (map (match-lambda (#(drv) drv))
+ (sqlite-exec db "
+SELECT DISTINCT derivation FROM (
+ SELECT Derivations.derivation FROM Derivations INNER JOIN Builds
+ WHERE Derivations.derivation = Builds.derivation AND Builds.status < 0
+);")))
+
(define (db-get-stamp db spec)
"Return a stamp corresponding to specification SPEC in database DB."
(let ((res (sqlite-exec db "SELECT * FROM Stamps WHERE specification="