Commit 242c5de0 authored by Stan Hu's avatar Stan Hu

Memoize the global default for push rules within the request

When pushing many references, the global default setting is repeatedly
retrieved from the schema cache, which can bog down performance to the
point where unicorn times out.

Closes #6465
parent 6a4853fc
class PushRule < ActiveRecord::Base
extend Gitlab::Cache::RequestCache
request_cache_key do
[self.id]
end
MatchError = Class.new(StandardError)
REGEX_COLUMNS = %i[
......@@ -131,7 +137,7 @@ class PushRule < ActiveRecord::Base
!regexp_uses_re2?
end
def read_setting_with_global_default(setting)
request_cache def read_setting_with_global_default(setting)
value = read_attribute(setting)
# return if value is true/false or if current object is the global setting
......
---
title: Memoize the global default for push rules within the request
merge_request:
author:
type: performance
......@@ -223,6 +223,21 @@ describe PushRule do
end
end
context 'with caching', :request_store do
let(:push_rule_second) { create(:push_rule) }
it 'memoizes the right push rules' do
expect(described_class).to receive(:global).twice.and_return(global_push_rule)
expect(global_push_rule).to receive(:public_send).with(:commit_committer_check).and_return(false)
expect(global_push_rule).to receive(:public_send).with(:reject_unsigned_commits).and_return(true)
2.times do
expect(push_rule.commit_committer_check).to be_falsey
expect(push_rule_second.reject_unsigned_commits).to be_truthy
end
end
end
describe '#available?' do
shared_examples 'an unavailable push_rule' do
it 'is not available' 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