Commit 7fad50ba authored by Stan Hu's avatar Stan Hu

Disable commit checks when no push rules are active

The refactoring in 0a8db3dc
inadvertently caused commit checks to become active regardless of
whether any rules were actually active. This significantly slowed pushes
and caused repositories with large number of commits to time out.

We fix this by using `push_rule_checks_commit?` since the existence of a
`PushRule` is not sufficient to determine whether any rules are
active. This also eliminates the need to override
`should_run_diff_validations?`, since the set of validations will only
contain the active ones.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/57067
parent 016c4c1b
---
title: Disable commit checks when no push rules are active
merge_request: 9569
author:
type: performance
......@@ -9,11 +9,6 @@ module EE
private
override :should_run_diff_validations?
def should_run_diff_validations?
super || validate_path_locks? || push_rule_checks_commit?
end
def validate_path_locks?
strong_memoize(:validate_path_locks) do
project.feature_available?(:file_locks) &&
......@@ -32,7 +27,7 @@ module EE
def validations_for_diff
super.tap do |validations|
validations.push(path_locks_validation) if validate_path_locks?
validations.push(file_name_validation) if push_rule
validations.push(file_name_validation) if push_rule_checks_commit?
end
end
......
......@@ -6,6 +6,16 @@ describe Gitlab::Checks::DiffCheck do
include_context 'push rules checks context'
describe '#validate!' do
context 'no push rules active' do
set(:push_rule) { create(:push_rule) }
it "does not attempt to check commits" do
expect(subject).not_to receive(:process_commits)
subject.validate!
end
end
context 'file name rules' do
# Notice that the commit used creates a file named 'README'
context 'file name regex check' do
......
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