Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzegorz@gitlab.com>2017-10-02 10:11:50 +0300
committerRobert Speicher <rspeicher@gmail.com>2017-10-02 12:52:10 +0300
commit450c98a6c0ff20e33383e2c5b04dfd6243599db6 (patch)
tree81ada2b7188530640e77afc8be23bd0af7a3425e
parent886511fd18cb3e7bf7f3853432cfe6a3a9f2a705 (diff)
Merge branch 'sh-fix-issue-38646' into 'master'
Fix pushes to an empty repository not invalidating has_visible_content? cache Closes #38646 See merge request gitlab-org/gitlab-ce!14613
-rw-r--r--app/models/repository.rb9
-rw-r--r--changelogs/unreleased/sh-fix-issue-38646.yml5
-rw-r--r--spec/models/repository_spec.rb13
3 files changed, 23 insertions, 4 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 4cb9f1baffd..a032df89e2d 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -33,7 +33,10 @@ class Repository
CACHED_METHODS = %i(size commit_count rendered_readme contribution_guide
changelog license_blob license_key gitignore koding_yml
gitlab_ci_yml branch_names tag_names branch_count
- tag_count avatar exists? empty? root_ref).freeze
+ tag_count avatar exists? empty? root_ref has_visible_content?).freeze
+
+ # Methods that use cache_method but only memoize the value
+ MEMOIZED_CACHED_METHODS = %i(license empty_repo?).freeze
# Certain method caches should be refreshed when certain types of files are
# changed. This Hash maps file types (as returned by Gitlab::FileDetector) to
@@ -268,7 +271,7 @@ class Repository
end
def expire_branches_cache
- expire_method_caches(%i(branch_names branch_count))
+ expire_method_caches(%i(branch_names branch_count has_visible_content?))
@local_branches = nil
@branch_exists_memo = nil
end
@@ -339,7 +342,7 @@ class Repository
def expire_emptiness_caches
return unless empty?
- expire_method_caches(%i(empty?))
+ expire_method_caches(%i(empty? has_visible_content?))
end
def lookup_cache
diff --git a/changelogs/unreleased/sh-fix-issue-38646.yml b/changelogs/unreleased/sh-fix-issue-38646.yml
new file mode 100644
index 00000000000..5c205775662
--- /dev/null
+++ b/changelogs/unreleased/sh-fix-issue-38646.yml
@@ -0,0 +1,5 @@
+---
+title: Fix pushes to an empty repository not invalidating has_visible_content? cache
+merge_request:
+author:
+type: fixed
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index d76ab421553..b46a19bfbb7 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -1275,6 +1275,7 @@ describe Repository, models: true do
allow(repository).to receive(:empty?).and_return(true)
expect(cache).to receive(:expire).with(:empty?)
+ expect(cache).to receive(:expire).with(:has_visible_content?)
repository.expire_emptiness_caches
end
@@ -1283,6 +1284,7 @@ describe Repository, models: true do
allow(repository).to receive(:empty?).and_return(false)
expect(cache).not_to receive(:expire).with(:empty?)
+ expect(cache).not_to receive(:expire).with(:has_visible_content?)
repository.expire_emptiness_caches
end
@@ -1613,7 +1615,7 @@ describe Repository, models: true do
describe '#expire_branches_cache' do
it 'expires the cache' do
expect(repository).to receive(:expire_method_caches)
- .with(%i(branch_names branch_count))
+ .with(%i(branch_names branch_count has_visible_content?))
.and_call_original
repository.expire_branches_cache
@@ -1874,6 +1876,15 @@ describe Repository, models: true do
repository.expire_all_method_caches
end
+
+ it 'all cache_method definitions are in the lists of method caches' do
+ methods = repository.methods.map do |method|
+ match = /^_uncached_(.*)/.match(method)
+ match[1].to_sym if match
+ end.compact
+
+ expect(methods).to match_array(Repository::CACHED_METHODS + Repository::MEMOIZED_CACHED_METHODS)
+ end
end
describe '#file_on_head' do