diff --git a/lib/builder_web.ml b/lib/builder_web.ml index b686262..54ec98b 100644 --- a/lib/builder_web.ml +++ b/lib/builder_web.ml @@ -552,15 +552,12 @@ let routes ~datadir ~cachedir ~configdir ~expired_jobs = in - let resolve_artifact id_opt conn = - let default_file : Builder_db.file = { - filepath = Fpath.v "null"; - sha256 = "0"; - size = -1; - } in + let resolve_artifact_size id_opt conn = match id_opt with - | None -> Lwt.return_ok default_file - | Some id -> Model.build_artifact_by_id id conn + | None -> Lwt.return_ok None + | Some id -> + Model.build_artifact_by_id id conn >|= fun file -> + Some file.size in @@ -584,16 +581,16 @@ let routes ~datadir ~cachedir ~configdir ~expired_jobs = Model.build_artifact_data datadir >>= fun build_env_right -> Model.build_artifact build_right.Builder_db.Build.uuid (Fpath.v "system-packages") conn >>= Model.build_artifact_data datadir >>= fun system_packages_right -> - resolve_artifact build_left.Builder_db.Build.main_binary conn >>= fun build_left_file -> - resolve_artifact build_right.Builder_db.Build.main_binary conn >>= fun build_right_file -> + resolve_artifact_size build_left.Builder_db.Build.main_binary conn >>= fun build_left_file_size -> + resolve_artifact_size build_right.Builder_db.Build.main_binary conn >>= fun build_right_file_size -> Model.job_name build_left.job_id conn >>= fun job_left -> Model.job_name build_right.job_id conn >|= fun job_right -> - (job_left, job_right, build_left, build_right, build_left_file, - build_right_file, switch_left, build_env_left, system_packages_left, + (job_left, job_right, build_left, build_right, build_left_file_size, + build_right_file_size, switch_left, build_env_left, system_packages_left, switch_right, build_env_right, system_packages_right)) |> if_error "Internal server error" - >>= fun (job_left, job_right, build_left, build_right, build_left_file, - build_right_file, switch_left, build_env_left, system_packages_left, + >>= fun (job_left, job_right, build_left, build_right, build_left_file_size, + build_right_file_size, switch_left, build_env_left, system_packages_left, switch_right, build_env_right, system_packages_right) -> let env_diff = Utils.compare_env build_env_left build_env_right and pkg_diff = Utils.compare_pkgs system_packages_left system_packages_right @@ -601,16 +598,17 @@ let routes ~datadir ~cachedir ~configdir ~expired_jobs = let switch_left = OpamFile.SwitchExport.read_from_string switch_left and switch_right = OpamFile.SwitchExport.read_from_string switch_right in let opam_diff = Opamdiff.compare switch_left switch_right in - (job_left, job_right, build_left, build_right, build_left_file, build_right_file, env_diff, pkg_diff, opam_diff) + (job_left, job_right, build_left, build_right, build_left_file_size, build_right_file_size, env_diff, pkg_diff, opam_diff) |> Lwt.return_ok in let compare_builds req = process_comparison req >>= fun - (job_left, job_right, build_left, build_right, build_left_file, build_right_file, env_diff, pkg_diff, opam_diff) -> + (job_left, job_right, build_left, build_right, build_left_file_size, build_right_file_size, env_diff, pkg_diff, opam_diff) -> match Dream.header req "Accept" with | Some accept when String.starts_with ~prefix:"application/json" accept -> + let file_size_json = Option.fold ~none:`Null ~some:(fun size -> `Int size) in let json_response = `Assoc [ "left", `Assoc [ @@ -619,7 +617,7 @@ let routes ~datadir ~cachedir ~configdir ~expired_jobs = "platform", `String build_left.platform; "build_start_time", `String (Ptime.to_rfc3339 build_left.start); "build_finish_time", `String (Ptime.to_rfc3339 build_left.finish); - "build_size", `Int (build_left_file.size) + "build_size", file_size_json build_left_file_size; ]; "right", `Assoc [ "job", `String job_right; @@ -627,7 +625,7 @@ let routes ~datadir ~cachedir ~configdir ~expired_jobs = "platform", `String build_right.platform; "build_start_time", `String (Ptime.to_rfc3339 build_right.start); "build_finish_time", `String (Ptime.to_rfc3339 build_right.finish); - "build_size", `Int (build_right_file.size) + "build_size", file_size_json build_right_file_size; ]; "env_diff", Utils.diff_map_to_json env_diff; "package_diff", Utils.diff_map_to_json pkg_diff;