Skip to content
Snippets Groups Projects
Commit d92c450b authored by Bob Van Landuyt's avatar Bob Van Landuyt
Browse files

Merge branch 'set_expiration_key_for_protected_branches' into 'master'

Set expire_in for protected branch cache keys

See merge request !91410
parents 2e69038c 25f56929
No related branches found
No related tags found
1 merge request!91410Set expire_in for protected branch cache keys
Pipeline #577911560 passed
......@@ -4,6 +4,8 @@ class ProtectedBranch < ApplicationRecord
include ProtectedRef
include Gitlab::SQL::Pattern
CACHE_EXPIRE_IN = 1.hour
scope :requiring_code_owner_approval,
-> { where(code_owner_approval_required: true) }
......@@ -29,7 +31,7 @@ def self.protected?(project, ref_name)
return true if project.empty_repo? && project.default_branch_protected?
return false if ref_name.blank?
Rails.cache.fetch(protected_ref_cache_key(project, ref_name)) do
Rails.cache.fetch(protected_ref_cache_key(project, ref_name), expires_in: CACHE_EXPIRE_IN) do
self.matching(ref_name, protected_refs: protected_refs(project)).present?
end
end
......
......@@ -190,6 +190,14 @@
expect(described_class).not_to receive(:matching)
expect(described_class.protected?(project, protected_branch.name)).to eq(true)
end
it 'sets expires_in for a cache key' do
cache_key = described_class.protected_ref_cache_key(project, protected_branch.name)
expect(Rails.cache).to receive(:fetch).with(cache_key, expires_in: 1.hour)
described_class.protected?(project, protected_branch.name)
end
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment