summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2018-03-08 10:33:59 +0000
committerSean McGivern <sean@mcgivern.me.uk>2018-03-08 10:33:59 +0000
commit15b4e9815e88de7a1ef0eda1603685c49ae80aa1 (patch)
tree7344414579e5724ee8c5c82a82f1cd48dd77ae35
parent0a6c82ea52ae1b1d62003dd303c687cef4508952 (diff)
parent611929eb96c0ee9f07d98163d0610325d8a2a322 (diff)
downloadgitlab-ce-15b4e9815e88de7a1ef0eda1603685c49ae80aa1.tar.gz
Merge branch 'sh-remove-double-caching-repo-empty' into 'master'
Remove double caching of Repository#empty? Closes #43882 See merge request gitlab-org/gitlab-ce!17588
-rw-r--r--app/models/repository.rb8
-rw-r--r--changelogs/unreleased/sh-remove-double-caching-repo-empty.yml5
-rw-r--r--spec/models/repository_spec.rb2
3 files changed, 10 insertions, 5 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 461dfbec2bc..386fd0b1c9a 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -35,7 +35,7 @@ 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 has_visible_content?
+ tag_count avatar exists? root_ref has_visible_content?
issue_template_names merge_request_template_names).freeze
# Methods that use cache_method but only memoize the value
@@ -360,7 +360,7 @@ class Repository
def expire_emptiness_caches
return unless empty?
- expire_method_caches(%i(empty? has_visible_content?))
+ expire_method_caches(%i(has_visible_content?))
end
def lookup_cache
@@ -506,12 +506,14 @@ class Repository
end
cache_method :exists?
+ # We don't need to cache the output of this method because both exists? and
+ # has_visible_content? are already memoized and cached. There's no guarantee
+ # that the values are expired and loaded atomically.
def empty?
return true unless exists?
!has_visible_content?
end
- cache_method :empty?
# The size of this repository in megabytes.
def size
diff --git a/changelogs/unreleased/sh-remove-double-caching-repo-empty.yml b/changelogs/unreleased/sh-remove-double-caching-repo-empty.yml
new file mode 100644
index 00000000000..1684be4e5e3
--- /dev/null
+++ b/changelogs/unreleased/sh-remove-double-caching-repo-empty.yml
@@ -0,0 +1,5 @@
+---
+title: Remove double caching of Repository#empty?
+merge_request:
+author:
+type: fixed
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index 579069ffa14..93a61c6ea71 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -1447,7 +1447,6 @@ describe Repository do
it 'expires the caches for an empty repository' 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
@@ -1456,7 +1455,6 @@ describe Repository do
it 'does not expire the cache for a non-empty repository' 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