Commit ddb2de09 authored by Jacob Vosmaer's avatar Jacob Vosmaer Committed by Rémy Coutable

Merge branch 'project-cache-worker-without-diverging' into 'master'

Removed diverging commit count calculation from Repository#build_cache

Using a repository with 1000 branches the old `Repository#build_cache` method would take around 180 seconds to complete. Without calculating the diverging commit counts this method "only" takes around 60 seconds. 

See commit 28cc2413eb5ddf920ce0b5eed803121f8b884754 for more details. This fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/14058

cc @rspeicher 

See merge request !3274
parent c85085b7
...@@ -227,12 +227,6 @@ class Repository ...@@ -227,12 +227,6 @@ class Repository
send(key) send(key)
end end
end end
branches.each do |branch|
unless cache.exist?(:"diverging_commit_counts_#{branch.name}")
send(:diverging_commit_counts, branch)
end
end
end end
def expire_tags_cache def expire_tags_cache
...@@ -301,18 +295,6 @@ class Repository ...@@ -301,18 +295,6 @@ class Repository
@tag_count = nil @tag_count = nil
end end
def rebuild_cache
cache_keys.each do |key|
cache.expire(key)
send(key)
end
branches.each do |branch|
cache.expire(:"diverging_commit_counts_#{branch.name}")
diverging_commit_counts(branch)
end
end
def lookup_cache def lookup_cache
@lookup_cache ||= {} @lookup_cache ||= {}
end end
......
...@@ -780,4 +780,34 @@ describe Repository, models: true do ...@@ -780,4 +780,34 @@ describe Repository, models: true do
end end
end end
end end
describe '#build_cache' do
let(:cache) { repository.send(:cache) }
it 'builds the caches if they do not already exist' do
expect(cache).to receive(:exist?).
exactly(repository.cache_keys.length).
times.
and_return(false)
repository.cache_keys.each do |key|
expect(repository).to receive(key)
end
repository.build_cache
end
it 'does not build any caches that already exist' do
expect(cache).to receive(:exist?).
exactly(repository.cache_keys.length).
times.
and_return(true)
repository.cache_keys.each do |key|
expect(repository).to_not receive(key)
end
repository.build_cache
end
end
end end
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