Commit d0e2cd52 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Add limit to recent_diff_head_shas as an argument

parent 06c97c26
...@@ -14,7 +14,7 @@ module Ci ...@@ -14,7 +14,7 @@ module Ci
attr_reader :merge_request, :current_user attr_reader :merge_request, :current_user
delegate :merge_request_diffs, :commit_shas, :target_project, :source_project, :source_branch, to: :merge_request delegate :recent_diff_head_shas, :commit_shas, :target_project, :source_project, :source_branch, to: :merge_request
# Fetch all pipelines that the user can read. # Fetch all pipelines that the user can read.
def execute def execute
...@@ -84,7 +84,7 @@ module Ci ...@@ -84,7 +84,7 @@ module Ci
def all_pipelines_for_merge_request def all_pipelines_for_merge_request
if Feature.enabled?(:decomposed_ci_query_in_pipelines_for_merge_request_finder, source_project, default_enabled: :yaml) if Feature.enabled?(:decomposed_ci_query_in_pipelines_for_merge_request_finder, source_project, default_enabled: :yaml)
pipelines_for_merge_request = triggered_by_merge_request pipelines_for_merge_request = triggered_by_merge_request
pipelines_for_branch = triggered_for_branch.for_sha(recent_diff_head_shas) 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]) Ci::Pipeline.from_union([pipelines_for_merge_request, pipelines_for_branch])
else else
...@@ -92,11 +92,6 @@ module Ci ...@@ -92,11 +92,6 @@ module Ci
end end
end end
def recent_diff_head_shas
# We're limiting the number of commits' SHAs to 100 since they are used in a WHERE clause of a query
merge_request_diffs.recent.limit(COMMITS_LIMIT).pluck(:head_commit_sha).uniq # rubocop: disable CodeReuse/ActiveRecord
end
# NOTE: this method returns only parent merge request pipelines. # NOTE: this method returns only parent merge request pipelines.
# Child merge request pipelines have a different source. # Child merge request pipelines have a different source.
def triggered_by_merge_request def triggered_by_merge_request
......
...@@ -1658,8 +1658,8 @@ class MergeRequest < ApplicationRecord ...@@ -1658,8 +1658,8 @@ class MergeRequest < ApplicationRecord
service_class.new(project, current_user, id: id, report_type: report_type).execute(comparison_base_pipeline(identifier), actual_head_pipeline) service_class.new(project, current_user, id: id, report_type: report_type).execute(comparison_base_pipeline(identifier), actual_head_pipeline)
end end
def recent_diff_head_shas def recent_diff_head_shas(limit = 100)
merge_request_diffs.recent.pluck(:head_commit_sha) merge_request_diffs.recent(limit).pluck(:head_commit_sha)
end end
def all_commits def all_commits
......
...@@ -66,7 +66,7 @@ class MergeRequestDiff < ApplicationRecord ...@@ -66,7 +66,7 @@ class MergeRequestDiff < ApplicationRecord
joins(:merge_request).where(merge_requests: { target_project_id: project_id }) joins(:merge_request).where(merge_requests: { target_project_id: project_id })
end end
scope :recent, -> { order(id: :desc).limit(100) } scope :recent, -> (limit = 100) { order(id: :desc).limit(limit) }
scope :files_in_database, -> do scope :files_in_database, -> do
where(stored_externally: [false, nil]).where(arel_table[:files_count].gt(0)) where(stored_externally: [false, nil]).where(arel_table[:files_count].gt(0))
......
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