diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-18 20:02:30 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-18 20:02:30 +0000 |
commit | 41fe97390ceddf945f3d967b8fdb3de4c66b7dea (patch) | |
tree | 9c8d89a8624828992f06d892cd2f43818ff5dcc8 /app/models/preloaders | |
parent | 0804d2dc31052fb45a1efecedc8e06ce9bc32862 (diff) | |
download | gitlab-ce-41fe97390ceddf945f3d967b8fdb3de4c66b7dea.tar.gz |
Add latest changes from gitlab-org/gitlab@14-9-stable-eev14.9.0-rc42
Diffstat (limited to 'app/models/preloaders')
-rw-r--r-- | app/models/preloaders/environments/deployment_preloader.rb | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/app/models/preloaders/environments/deployment_preloader.rb b/app/models/preloaders/environments/deployment_preloader.rb index fcf892698bb..251d1837f19 100644 --- a/app/models/preloaders/environments/deployment_preloader.rb +++ b/app/models/preloaders/environments/deployment_preloader.rb @@ -21,11 +21,13 @@ module Preloaders def load_deployment_association(association_name, association_attributes) return unless environments.present? - union_arg = environments.inject([]) do |result, environment| - result << environment.association(association_name).scope - end - - union_sql = Deployment.from_union(union_arg).to_sql + # Not using Gitlab::SQL::Union as `order_by` in the SQL constructed is ignored. + # See: + # 1) https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/sql/union.rb#L7 + # 2) https://gitlab.com/gitlab-org/gitlab/-/issues/353966#note_860928647 + union_sql = environments.map do |environment| + "(#{environment.association(association_name).scope.to_sql})" + end.join(' UNION ') deployments = Deployment .from("(#{union_sql}) #{::Deployment.table_name}") @@ -34,8 +36,16 @@ module Preloaders deployments_by_environment_id = deployments.index_by(&:environment_id) environments.each do |environment| - environment.association(association_name).target = deployments_by_environment_id[environment.id] + associated_deployment = deployments_by_environment_id[environment.id] + + environment.association(association_name).target = associated_deployment environment.association(association_name).loaded! + + if associated_deployment + # `last?` in DeploymentEntity requires this environment to be loaded + associated_deployment.association(:environment).target = environment + associated_deployment.association(:environment).loaded! + end end end end |