summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-02-20 16:23:54 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2016-02-20 19:37:19 +0100
commitb0585544ea5e5bcb25afb734bb49e0ea87da0c78 (patch)
tree623dcd862752626269b7d9fa528a82f4de1a9d22
parent040ae7e3e0c6f4d97fe6366bff9b05831283db7e (diff)
downloadgitlab-ce-flush-cache-web-editor.tar.gz
Flush emptiness caches whenever neededflush-cache-web-editor
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
-rw-r--r--app/models/repository.rb4
-rw-r--r--spec/models/repository_spec.rb14
2 files changed, 18 insertions, 0 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index be30a3b0906..e050bd45254 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -239,6 +239,10 @@ class Repository
end
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
# Expires _all_ caches, including those that would normally only be expired
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index 9242f755449..106bcbdf744 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -361,6 +361,20 @@ describe Repository, models: true do
repository.expire_cache('master')
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_cache)
+
+ 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_cache)
+
+ repository.expire_cache
+ end
end
describe '#expire_root_ref_cache' do