summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <contact@jacobvosmaer.nl>2016-03-18 11:28:54 +0000
committerJacob Vosmaer <contact@jacobvosmaer.nl>2016-03-18 11:28:54 +0000
commitbca8ea33b3dcca926bbb3fe3a75d0dca33215f8f (patch)
treee8f758662fcbcab2ba97e65822031ab84c6e33dd
parent4cd87d31bd2d8401dbfa968494a3fc7a869dbf2d (diff)
parentdd4b789765ca4219f89c03d14d0c2524b2374184 (diff)
downloadgitlab-ce-bca8ea33b3dcca926bbb3fe3a75d0dca33215f8f.tar.gz
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
-rw-r--r--app/models/repository.rb18
-rw-r--r--spec/models/repository_spec.rb30
2 files changed, 30 insertions, 18 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 036919c27b2..25d24493f6e 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -227,12 +227,6 @@ class Repository
send(key)
end
end
-
- branches.each do |branch|
- unless cache.exist?(:"diverging_commit_counts_#{branch.name}")
- send(:diverging_commit_counts, branch)
- end
- end
end
def expire_tags_cache
@@ -301,18 +295,6 @@ class Repository
@tag_count = nil
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
@lookup_cache ||= {}
end
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index 536fe66b21b..a57229a4fdf 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -780,4 +780,34 @@ describe Repository, models: true do
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