Flush emptiness caches whenever needed
This ensures that the emptiness cache (used for Repository#empty? and Repository#has_visible_content?) is flushed after comitting changes (using the web editor, API or Git) for new repositories. Once a repository is no longer empty there's no need to explicitly flush the cache for Repository#empty?. The cache for Repository#has_visible_content? in turn is already flushed whenever needed. Fixes gitlab-org/gitlab-ce#13387
This commit is contained in:
parent
040ae7e3e0
commit
e0cb3212ed
|
@ -239,6 +239,10 @@ class Repository
|
||||||
end
|
end
|
||||||
|
|
||||||
expire_branch_cache(branch_name)
|
expire_branch_cache(branch_name)
|
||||||
|
|
||||||
|
# This ensures this particular cache is flushed after the first commit to a
|
||||||
|
# new repository.
|
||||||
|
expire_emptiness_caches if empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Expires _all_ caches, including those that would normally only be expired
|
# Expires _all_ caches, including those that would normally only be expired
|
||||||
|
|
|
@ -361,6 +361,20 @@ describe Repository, models: true do
|
||||||
|
|
||||||
repository.expire_cache('master')
|
repository.expire_cache('master')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'expires the emptiness cache for an empty repository' do
|
||||||
|
expect(repository).to receive(:empty?).and_return(true)
|
||||||
|
expect(repository).to receive(:expire_emptiness_caches)
|
||||||
|
|
||||||
|
repository.expire_cache
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not expire the emptiness cache for a non-empty repository' do
|
||||||
|
expect(repository).to receive(:empty?).and_return(false)
|
||||||
|
expect(repository).to_not receive(:expire_emptiness_caches)
|
||||||
|
|
||||||
|
repository.expire_cache
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#expire_root_ref_cache' do
|
describe '#expire_root_ref_cache' do
|
||||||
|
|
Loading…
Reference in New Issue