Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
58df8b53
Commit
58df8b53
authored
Oct 02, 2019
by
Dylan Griffith
Committed by
Stan Hu
Oct 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix stale caching of Repository#has_visible_content?
parent
43dcd3e4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
22 deletions
+15
-22
app/models/repository.rb
app/models/repository.rb
+1
-1
changelogs/unreleased/cache-issues-with-has_visible_content.yml
...logs/unreleased/cache-issues-with-has_visible_content.yml
+5
-0
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+9
-21
No files found.
app/models/repository.rb
View file @
58df8b53
...
...
@@ -568,7 +568,7 @@ class Repository
delegate
:branch_count
,
:tag_count
,
:has_visible_content?
,
to: :raw_repository
cache_method
:branch_count
,
fallback:
0
cache_method
:tag_count
,
fallback:
0
cache_method
:has_visible_content?
,
fallback:
false
cache_method
_asymmetrically
:has_visible_content?
def
avatar
# n+1: https://gitlab.com/gitlab-org/gitlab-foss/issues/38327
...
...
changelogs/unreleased/cache-issues-with-has_visible_content.yml
0 → 100644
View file @
58df8b53
---
title
:
Use cache_method_asymmetrically with Repository#has_visible_content?
merge_request
:
17975
author
:
type
:
fixed
spec/models/repository_spec.rb
View file @
58df8b53
...
...
@@ -1193,33 +1193,21 @@ describe Repository do
end
describe
'#has_visible_content?'
do
before
do
# If raw_repository.has_visible_content? gets called more than once then
# caching is broken. We don't want that.
it
'delegates to raw_repository when true'
do
expect
(
repository
.
raw_repository
).
to
receive
(
:has_visible_content?
)
.
once
.
and_return
(
result
)
end
.
and_return
(
true
)
context
'when true'
do
let
(
:result
)
{
true
}
it
'returns true and caches it'
do
expect
(
repository
.
has_visible_content?
).
to
eq
(
true
)
# Second call hits the cache
expect
(
repository
.
has_visible_content?
).
to
eq
(
true
)
end
end
context
'when false'
do
let
(
:result
)
{
false
}
it
'delegates to raw_repository when false'
do
expect
(
repository
.
raw_repository
).
to
receive
(
:has_visible_content?
)
.
and_return
(
false
)
it
'returns false and caches it'
do
expect
(
repository
.
has_visible_content?
).
to
eq
(
false
)
# Second call hits the cache
expect
(
repository
.
has_visible_content?
).
to
eq
(
false
)
end
end
it_behaves_like
'asymmetric cached method'
,
:has_visible_content?
end
describe
'#branch_exists?'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment