aboutsummaryrefslogtreecommitdiff
path: root/guix-data-service
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2024-06-21 15:08:37 +0100
committerChristopher Baines <mail@cbaines.net>2024-06-21 15:29:34 +0100
commite6205e988ae95c5dca57cf257a90b87e06dd16a7 (patch)
tree4dbdca37bed2707e1777808d27fe8fc0e0c9447b /guix-data-service
parent4e7c2bcfbf847d4276c20153b26450a0cd2990af (diff)
downloaddata-service-e6205e988ae95c5dca57cf257a90b87e06dd16a7.tar
data-service-e6205e988ae95c5dca57cf257a90b87e06dd16a7.tar.gz
Speed up querying for revision package derivations
By splitting it up by system.
Diffstat (limited to 'guix-data-service')
-rw-r--r--guix-data-service/model/derivation.scm41
-rw-r--r--guix-data-service/web/revision/controller.scm47
2 files changed, 49 insertions, 39 deletions
diff --git a/guix-data-service/model/derivation.scm b/guix-data-service/model/derivation.scm
index 170be49..02fd175 100644
--- a/guix-data-service/model/derivation.scm
+++ b/guix-data-service/model/derivation.scm
@@ -198,7 +198,7 @@ ORDER BY systems.system DESC,
(define* (select-package-derivations-in-revision conn
commit-hash
#:key
- systems
+ system
targets
minimum-builds
maximum-builds
@@ -214,19 +214,25 @@ ORDER BY systems.system DESC,
(string-join
`(,@(filter-map
(lambda (field values)
- (if values
- (string-append
- field " IN ("
- (string-join (map (lambda (value)
- (simple-format #f "'~A'" value))
- values)
- ",")
- ")")
- #f))
- '("systems.system"
- "target")
- (list systems
- targets))
+ (cond
+ ((list? values)
+ (string-append
+ field " IN ("
+ (string-join (map (lambda (value)
+ (simple-format #f "'~A'" value))
+ values)
+ ",")
+ ")"))
+ ((number? values)
+ (string-append
+ field " = " (number->string values)))
+ (else
+ #f)))
+ '("package_derivations.system_id" "target")
+ (list
+ (and=> system (lambda (system)
+ (system->system-id conn system)))
+ targets))
,@(if minimum-builds
(list
(string-append
@@ -346,7 +352,6 @@ EXISTS (
(string-append
"
SELECT derivations.file_name,
- systems.system,
package_derivations.target"
(if include-builds?
",
@@ -371,8 +376,6 @@ SELECT derivations.file_name,
"")
"
FROM derivations
-INNER JOIN systems
- ON derivations.system_id = systems.id
INNER JOIN derivations_by_output_details_set
ON derivations.id = derivations_by_output_details_set.derivation_id
INNER JOIN package_derivations
@@ -400,7 +403,7 @@ ORDER BY derivations.file_name
"")))
(map (match-lambda
- ((file_name system target builds)
+ ((file_name target builds)
(list file_name
system
target
@@ -408,7 +411,7 @@ ORDER BY derivations.file_name
(eq? #f builds))
#()
(json-string->scm builds))))
- ((file_name system target)
+ ((file_name target)
(list file_name system target)))
(exec-query conn
query
diff --git a/guix-data-service/web/revision/controller.scm b/guix-data-service/web/revision/controller.scm
index aa7f226..5aeed49 100644
--- a/guix-data-service/web/revision/controller.scm
+++ b/guix-data-service/web/revision/controller.scm
@@ -1069,8 +1069,8 @@
(assq-ref query-parameters 'field)))
(letpar&
((derivations
- (with-resource-from-pool (connection-pool) conn
- (if search-query
+ (if search-query
+ (with-resource-from-pool (connection-pool) conn
(search-package-derivations-in-revision
conn
commit-hash
@@ -1088,24 +1088,31 @@
string->symbol)
#:limit-results limit-results
#:after-name (assq-ref query-parameters 'after_name)
- #:include-builds? (member "builds" fields))
- (select-package-derivations-in-revision
- conn
- commit-hash
- #:systems (assq-ref query-parameters 'system)
- #:targets (assq-ref query-parameters 'target)
- #:maximum-builds (assq-ref query-parameters 'maximum_builds)
- #:minimum-builds (assq-ref query-parameters 'minimum_builds)
- #:build-from-build-servers (assq-ref query-parameters
- 'build_from_build_server)
- #:no-build-from-build-servers (assq-ref query-parameters
- 'no_build_from_build_server)
- #:build-status (and=> (assq-ref query-parameters
- 'build_status)
- string->symbol)
- #:limit-results limit-results
- #:after-name (assq-ref query-parameters 'after_name)
- #:include-builds? (member "builds" fields)))))
+ #:include-builds? (member "builds" fields)))
+ (concatenate!
+ (par-map&
+ (lambda (system)
+ (with-resource-from-pool (connection-pool) conn
+ (select-package-derivations-in-revision
+ conn
+ commit-hash
+ #:system system
+ #:targets (assq-ref query-parameters 'target)
+ #:maximum-builds (assq-ref query-parameters 'maximum_builds)
+ #:minimum-builds (assq-ref query-parameters 'minimum_builds)
+ #:build-from-build-servers (assq-ref query-parameters
+ 'build_from_build_server)
+ #:no-build-from-build-servers (assq-ref query-parameters
+ 'no_build_from_build_server)
+ #:build-status (and=> (assq-ref query-parameters
+ 'build_status)
+ string->symbol)
+ #:limit-results limit-results
+ #:after-name (assq-ref query-parameters 'after_name)
+ #:include-builds? (member "builds" fields))))
+ (or (assq-ref query-parameters 'system)
+ (call-with-resource-from-pool (connection-pool)
+ list-systems))))))
(build-server-urls
(call-with-resource-from-pool (connection-pool)
select-build-server-urls-by-id)))