From e05fd9fe09ae17221b802443992f96cfce022dea Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sat, 7 Dec 2019 19:27:56 +0100 Subject: WIP speed up associating derivations with builds --- guix-data-service/model/derivation.scm | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'guix-data-service/model') diff --git a/guix-data-service/model/derivation.scm b/guix-data-service/model/derivation.scm index f26eeea..5d8df69 100644 --- a/guix-data-service/model/derivation.scm +++ b/guix-data-service/model/derivation.scm @@ -141,13 +141,25 @@ ORDER BY derivations.system DESC, ,@(if minimum-builds (list (string-append - "(SELECT COUNT(DISTINCT id) FROM builds WHERE derivation_file_name = derivations.file_name) >= " + " +( + SELECT COUNT(*) + FROM builds + WHERE builds.derivation_output_details_set_id = + derivations_by_output_details_set.derivation_output_details_set_id +) >= " (number->string minimum-builds))) '()) ,@(if maximum-builds (list (string-append - "(SELECT COUNT(DISTINCT id) FROM builds WHERE derivation_file_name = derivations.file_name) <= " + " +( + SELECT COUNT(*) + FROM builds + WHERE builds.derivation_output_details_set_id = + derivations_by_output_details_set.derivation_output_details_set_id +) <= " (number->string maximum-builds))) '())) " AND ")) @@ -176,15 +188,8 @@ SELECT derivations.file_name, ORDER BY build_id, timestamp DESC ) AS latest_build_status ON builds.id = latest_build_status.build_id - WHERE builds.derivation_file_name IN ( - SELECT dervs_for_file_names.file_name - FROM derivations AS dervs_for_file_names - WHERE ARRAY[dervs_for_file_names.id] <@ ( - SELECT equivalent_derivations.derivation_ids - FROM equivalent_derivations - WHERE ARRAY[derivations.id] <@ equivalent_derivations.derivation_ids - ) - ) + WHERE builds.derivation_output_details_set_id = + derivations_by_output_details_set.derivation_output_details_set_id ) AS builds, ( SELECT @@ -219,6 +224,8 @@ SELECT derivations.file_name, WHERE derivation_outputs.derivation_id = derivations.id ) AS outputs FROM derivations +INNER JOIN derivations_by_output_details_set + ON derivations.id = derivations_by_output_details_set.derivation_id INNER JOIN package_derivations ON derivations.id = package_derivations.derivation_id INNER JOIN guix_revision_package_derivations -- cgit v1.2.3