From 6c4f36bfba82e56ffd530e4a75988fdfddc4ac4a Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Wed, 22 Nov 2023 12:23:00 +0100 Subject: [PATCH 1/2] fix get_latest_successful_with_binary to only return builds with main_binary so-called successful builds. in a756f2c..3b98605f there were regressions (missing this condition in get_latest_succesful_with_binary, get_next_successful_different_output, get_previous_successful_different_output). --- db/builder_db.ml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/builder_db.ml b/db/builder_db.ml index 6ea1ba8..0704a7b 100644 --- a/db/builder_db.ml +++ b/db/builder_db.ml @@ -320,7 +320,7 @@ module Build = struct FROM build b LEFT JOIN build_artifact a ON b.main_binary = a.id - WHERE b.job = $1 AND b.platform = $2 + WHERE b.job = $1 AND b.platform = $2 AND b.main_binary IS NOT NULL ORDER BY b.start_d DESC, b.start_ps DESC LIMIT 1 |} @@ -348,6 +348,7 @@ module Build = struct FROM build b, build b0, build_artifact a, build_artifact a0 WHERE b0.id = ? AND b0.job = b.job AND b.platform = b0.platform AND + b.main_binary IS NOT NULL AND a.id = b.main_binary AND a0.id = b0.main_binary AND a.sha256 <> a0.sha256 AND (b0.start_d > b.start_d OR b0.start_d = b.start_d AND b0.start_ps > b.start_ps) @@ -364,6 +365,7 @@ module Build = struct FROM build b, build b0, build_artifact a, build_artifact a0 WHERE b0.id = ? AND b0.job = b.job AND b.platform = b0.platform AND + b.main_binary IS NOT NULL AND a.id = b.main_binary AND a0.id = b0.main_binary AND a.sha256 <> a0.sha256 AND (b0.start_d < b.start_d OR b0.start_d = b.start_d AND b0.start_ps < b.start_ps) From e262ae9d9078e85378914ffa67d919f826f1cfa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reynir=20Bj=C3=B6rnsson?= Date: Wed, 22 Nov 2023 13:43:09 +0100 Subject: [PATCH 2/2] Rewrite query to not use LEFT JOIN Since we now consider only builds with main binaries successfull we can rewrite get_latest_successful_with_binary to not use a LEFT JOIN. --- db/builder_db.ml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/db/builder_db.ml b/db/builder_db.ml index 0704a7b..cdcd190 100644 --- a/db/builder_db.ml +++ b/db/builder_db.ml @@ -311,16 +311,15 @@ module Build = struct |} let get_latest_successful_with_binary = - Caqti_type.(tup2 (id `job) string) ->? Caqti_type.tup3 (id `build) t file_opt @@ + Caqti_type.(tup2 (id `job) string) ->? Caqti_type.tup3 (id `build) t file @@ {| SELECT b.id, b.uuid, b.start_d, b.start_ps, b.finish_d, b.finish_ps, b.result_code, b.result_msg, b.console, b.script, b.platform, b.main_binary, b.input_id, b.user, b.job, a.filepath, a.localpath, a.sha256, a.size - FROM build b - LEFT JOIN build_artifact a ON - b.main_binary = a.id - WHERE b.job = $1 AND b.platform = $2 AND b.main_binary IS NOT NULL + FROM build b, build_artifact a + WHERE b.main_binary = a.id AND b.job = $1 AND b.platform = $2 + AND b.main_binary IS NOT NULL ORDER BY b.start_d DESC, b.start_ps DESC LIMIT 1 |}