diff options
Diffstat (limited to 'app/finders/ci/pipelines_for_merge_request_finder.rb')
-rw-r--r-- | app/finders/ci/pipelines_for_merge_request_finder.rb | 66 |
1 files changed, 14 insertions, 52 deletions
diff --git a/app/finders/ci/pipelines_for_merge_request_finder.rb b/app/finders/ci/pipelines_for_merge_request_finder.rb index 9476c30f525..b623a94541b 100644 --- a/app/finders/ci/pipelines_for_merge_request_finder.rb +++ b/app/finders/ci/pipelines_for_merge_request_finder.rb @@ -31,65 +31,27 @@ module Ci # Fetch all pipelines without permission check. def all - ::Gitlab::Database.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/336891') do - strong_memoize(:all_pipelines) do - next Ci::Pipeline.none unless source_project - - pipelines = - if merge_request.persisted? - all_pipelines_for_merge_request - else - triggered_for_branch.for_sha(commit_shas) - end - - sort(pipelines) - end - end - end - - private + strong_memoize(:all_pipelines) do + next Ci::Pipeline.none unless source_project - # rubocop: disable CodeReuse/ActiveRecord - def pipelines_using_cte - sha_relation = merge_request.all_commits.select(:sha).distinct - - 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) - - Ci::Pipeline.with(cte.to_arel) # rubocop: disable CodeReuse/ActiveRecord - .from_union([pipelines_for_merge_requests, pipelines_for_branch]) - end - # rubocop: enable CodeReuse/ActiveRecord + pipelines = + if merge_request.persisted? + all_pipelines_for_merge_request + else + triggered_for_branch.for_sha(commit_shas) + end - def filter_by_sha(pipelines, cte) - hex = Arel::Nodes::SqlLiteral.new("'hex'") - string_sha = Arel::Nodes::NamedFunction.new('encode', [cte.table[:sha], hex]) - join_condition = string_sha.eq(Ci::Pipeline.arel_table[:sha]) - - filter_by(pipelines, cte, join_condition) + sort(pipelines) + end end - def filter_by(pipelines, cte, join_condition) - shas_table = - Ci::Pipeline.arel_table - .join(cte.table, Arel::Nodes::InnerJoin) - .on(join_condition) - .join_sources - - pipelines.joins(shas_table) # rubocop: disable CodeReuse/ActiveRecord - end + private def all_pipelines_for_merge_request - if Feature.enabled?(:decomposed_ci_query_in_pipelines_for_merge_request_finder, target_project, default_enabled: :yaml) - pipelines_for_merge_request = triggered_by_merge_request - pipelines_for_branch = triggered_for_branch.for_sha(recent_diff_head_shas(COMMITS_LIMIT)) + pipelines_for_merge_request = triggered_by_merge_request + pipelines_for_branch = triggered_for_branch.for_sha(recent_diff_head_shas(COMMITS_LIMIT)) - Ci::Pipeline.from_union([pipelines_for_merge_request, pipelines_for_branch]) - else - pipelines_using_cte - end + Ci::Pipeline.from_union([pipelines_for_merge_request, pipelines_for_branch]) end # NOTE: this method returns only parent merge request pipelines. |