Commit fa16b84a authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'lm-fix-pipeline-dep-and-env-cross-joins' into 'master'

Fix cross join in MergeRequest#environments

See merge request gitlab-org/gitlab!71591
parents d9445328 0b9673eb
......@@ -1409,7 +1409,19 @@ class MergeRequest < ApplicationRecord
def environments
return Environment.none unless actual_head_pipeline&.merge_request?
actual_head_pipeline.environments
if ::Feature.enabled?(:avoid_cross_joins_environments_merge_request, default_enabled: :yaml)
build_for_actual_head_pipeline = Ci::Build.latest.where(pipeline: actual_head_pipeline)
environments = build_for_actual_head_pipeline.joins(:metadata)
.where.not('ci_builds_metadata.expanded_environment_name' => nil)
.distinct('ci_builds_metadata.expanded_environment_name')
.limit(100)
.pluck(:expanded_environment_name)
Environment.where(project: project, name: environments)
else
actual_head_pipeline.environments
end
end
def fetch_ref!
......
---
name: avoid_cross_joins_environments_merge_request
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/71591
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/343236
milestone: '14.5'
type: development
group: group::sharding
default_enabled: false
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment