From fc24ca2eac708695f663623a50f715db5ca914bd Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 5 Apr 2018 22:15:20 +0200 Subject: 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. --- src/cuirass/database.scm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src') 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=" -- cgit v1.2.3