Commit 76d01d28 authored by Adam Hegyi's avatar Adam Hegyi

Use DISTINCT in MR finder SHAs CTE

This change introduces a feature flag (use_distinct_in_shas_cte) that
calls distinct when looking up SHAs for an MR.
parent 71910be8
......@@ -45,8 +45,12 @@ module Ci
private
# rubocop: disable CodeReuse/ActiveRecord
def pipelines_using_cte
cte = Gitlab::SQL::CTE.new(:shas, merge_request.all_commits.select(:sha))
sha_relation = merge_request.all_commits.select(:sha)
sha_relation = sha_relation.distinct if Feature.enabled?(:use_distinct_in_shas_cte)
cte = Gitlab::SQL::CTE.new(:shas, sha_relation)
pipelines_for_merge_requests = triggered_by_merge_request
pipelines_for_branch = filter_by_sha(triggered_for_branch, cte)
......@@ -54,6 +58,7 @@ module Ci
Ci::Pipeline.with(cte.to_arel) # rubocop: disable CodeReuse/ActiveRecord
.from_union([pipelines_for_merge_requests, pipelines_for_branch])
end
# rubocop: enable CodeReuse/ActiveRecord
def filter_by_sha(pipelines, cte)
hex = Arel::Nodes::SqlLiteral.new("'hex'")
......
---
name: use_distinct_in_shas_cte
introduced_by_url:
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/330586
milestone: '13.12'
type: development
group: group::optimize
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