Skip to content
Snippets Groups Projects
Commit 00cd5d93 authored by Jacob Vosmaer (GitLab)'s avatar Jacob Vosmaer (GitLab) Committed by Rémy Coutable
Browse files

Use Redis cache for branch existence checks

parent 2822254e
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -217,11 +217,7 @@ class Repository
def branch_exists?(branch_name)
return false unless raw_repository
 
@branch_exists_memo ||= Hash.new do |hash, key|
hash[key] = raw_repository.branch_exists?(key)
end
@branch_exists_memo[branch_name]
branch_names.include?(branch_name)
end
 
def ref_exists?(ref)
Loading
Loading
Loading
Loading
@@ -1166,6 +1166,31 @@ describe Repository do
end
end
 
describe '#branch_exists?' do
it 'uses branch_names' do
allow(repository).to receive(:branch_names).and_return(['foobar'])
expect(repository.branch_exists?('foobar')).to eq(true)
expect(repository.branch_exists?('master')).to eq(false)
end
end
describe '#branch_names', :use_clean_rails_memory_store_caching do
let(:fake_branch_names) { ['foobar'] }
it 'gets cached across Repository instances' do
allow(repository.raw_repository).to receive(:branch_names).once.and_return(fake_branch_names)
expect(repository.branch_names).to eq(fake_branch_names)
fresh_repository = Project.find(project.id).repository
expect(fresh_repository.object_id).not_to eq(repository.object_id)
expect(fresh_repository.raw_repository).not_to receive(:branch_names)
expect(fresh_repository.branch_names).to eq(fake_branch_names)
end
end
describe '#update_autocrlf_option' do
describe 'when autocrlf is not already set to :input' do
before do
Loading
Loading
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