BigW Consortium Gitlab

Commit 8b0417aa by Grzegorz Bizon

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
parents b69aab6e 6188e449
...@@ -34,7 +34,10 @@ class Repository ...@@ -34,7 +34,10 @@ class Repository
CACHED_METHODS = %i(size commit_count rendered_readme contribution_guide CACHED_METHODS = %i(size commit_count rendered_readme contribution_guide
changelog license_blob license_key gitignore koding_yml changelog license_blob license_key gitignore koding_yml
gitlab_ci_yml branch_names tag_names branch_count 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 # Certain method caches should be refreshed when certain types of files are
# changed. This Hash maps file types (as returned by Gitlab::FileDetector) to # changed. This Hash maps file types (as returned by Gitlab::FileDetector) to
...@@ -269,7 +272,7 @@ class Repository ...@@ -269,7 +272,7 @@ class Repository
end end
def expire_branches_cache 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 @local_branches = nil
@branch_exists_memo = nil @branch_exists_memo = nil
end end
...@@ -340,7 +343,7 @@ class Repository ...@@ -340,7 +343,7 @@ class Repository
def expire_emptiness_caches def expire_emptiness_caches
return unless empty? return unless empty?
expire_method_caches(%i(empty?)) expire_method_caches(%i(empty? has_visible_content?))
end end
def lookup_cache def lookup_cache
......
---
title: Fix pushes to an empty repository not invalidating has_visible_content? cache
merge_request:
author:
type: fixed
...@@ -1272,6 +1272,7 @@ describe Repository do ...@@ -1272,6 +1272,7 @@ describe Repository do
allow(repository).to receive(:empty?).and_return(true) allow(repository).to receive(:empty?).and_return(true)
expect(cache).to receive(:expire).with(:empty?) expect(cache).to receive(:expire).with(:empty?)
expect(cache).to receive(:expire).with(:has_visible_content?)
repository.expire_emptiness_caches repository.expire_emptiness_caches
end end
...@@ -1280,6 +1281,7 @@ describe Repository do ...@@ -1280,6 +1281,7 @@ describe Repository do
allow(repository).to receive(:empty?).and_return(false) allow(repository).to receive(:empty?).and_return(false)
expect(cache).not_to receive(:expire).with(:empty?) expect(cache).not_to receive(:expire).with(:empty?)
expect(cache).not_to receive(:expire).with(:has_visible_content?)
repository.expire_emptiness_caches repository.expire_emptiness_caches
end end
...@@ -1609,7 +1611,7 @@ describe Repository do ...@@ -1609,7 +1611,7 @@ describe Repository do
describe '#expire_branches_cache' do describe '#expire_branches_cache' do
it 'expires the cache' do it 'expires the cache' do
expect(repository).to receive(:expire_method_caches) 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 .and_call_original
repository.expire_branches_cache repository.expire_branches_cache
...@@ -1888,6 +1890,15 @@ describe Repository do ...@@ -1888,6 +1890,15 @@ describe Repository do
repository.expire_all_method_caches repository.expire_all_method_caches
end 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 end
describe '#file_on_head' do describe '#file_on_head' do
......
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