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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
6d04f378
Commit
6d04f378
authored
Oct 19, 2017
by
Alejandro Rodríguez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid calling underlying methods on non-existing repos
This saves us Rugged/gRPC invocations
parent
00c15cc2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
8 deletions
+35
-8
app/models/repository.rb
app/models/repository.rb
+7
-2
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+28
-6
No files found.
app/models/repository.rb
View file @
6d04f378
...
...
@@ -1031,6 +1031,10 @@ class Repository
if
instance_variable_defined?
(
ivar
)
instance_variable_get
(
ivar
)
else
# If the repository doesn't exist and a fallback was specified we return
# that value inmediately. This saves us Rugged/gRPC invocations.
return
fallback
unless
fallback
.
nil?
||
exists?
begin
value
=
if
memoize_only
...
...
@@ -1040,8 +1044,9 @@ class Repository
end
instance_variable_set
(
ivar
,
value
)
rescue
Rugged
::
ReferenceError
,
Gitlab
::
Git
::
Repository
::
NoRepository
# if e.g. HEAD or the entire repository doesn't exist we want to
# gracefully handle this and not cache anything.
# Even if the above `#exists?` check passes these errors might still
# occur (for example because of a non-existing HEAD). We want to
# gracefully handle this and not cache anything
fallback
end
end
...
...
spec/models/repository_spec.rb
View file @
6d04f378
...
...
@@ -2110,19 +2110,41 @@ describe Repository do
end
describe
'#cache_method_output'
,
:use_clean_rails_memory_store_caching
do
let
(
:fallback
)
{
10
}
context
'with a non-existing repository'
do
let
(
:value
)
do
repository
.
cache_method_output
(
:cats
,
fallback:
10
)
do
raise
Rugged
::
ReferenceError
let
(
:project
)
{
create
(
:project
)
}
# No repository
subject
do
repository
.
cache_method_output
(
:cats
,
fallback:
fallback
)
do
repository
.
cats_call_stub
end
end
it
'returns a fallback value'
do
expect
(
value
).
to
eq
(
10
)
it
'returns the fallback value'
do
expect
(
subject
).
to
eq
(
fallback
)
end
it
'avoids calling the original method'
do
expect
(
repository
).
not_to
receive
(
:cats_call_stub
)
subject
end
end
context
'with a method throwing a non-existing-repository error'
do
subject
do
repository
.
cache_method_output
(
:cats
,
fallback:
fallback
)
do
raise
Gitlab
::
Git
::
Repository
::
NoRepository
end
end
it
'returns the fallback value'
do
expect
(
subject
).
to
eq
(
fallback
)
end
it
'does not cache the data'
do
value
subject
expect
(
repository
.
instance_variable_defined?
(
:@cats
)).
to
eq
(
false
)
expect
(
repository
.
send
(
:cache
).
exist?
(
:cats
)).
to
eq
(
false
)
...
...
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