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
555bb5a0
Commit
555bb5a0
authored
May 13, 2021
by
Robert May
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix for nested cache calls
parent
68b7a7f2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
2 deletions
+18
-2
lib/api/helpers/caching.rb
lib/api/helpers/caching.rb
+7
-1
spec/lib/api/helpers/caching_spec.rb
spec/lib/api/helpers/caching_spec.rb
+10
-0
spec/requests/api/branches_spec.rb
spec/requests/api/branches_spec.rb
+1
-1
No files found.
lib/api/helpers/caching.rb
View file @
555bb5a0
...
...
@@ -81,7 +81,13 @@ module API
# @return [Gitlab::Json::PrecompiledJson]
def
cache_action
(
key
,
**
cache_opts
)
json
=
cache
.
fetch
(
key
,
**
apply_default_cache_options
(
cache_opts
))
do
Gitlab
::
Json
.
dump
(
yield
.
as_json
)
response
=
yield
if
response
.
is_a?
(
Gitlab
::
Json
::
PrecompiledJson
)
response
.
to_s
else
Gitlab
::
Json
.
dump
(
response
.
as_json
)
end
end
body
Gitlab
::
Json
::
PrecompiledJson
.
new
(
json
)
...
...
spec/lib/api/helpers/caching_spec.rb
View file @
555bb5a0
...
...
@@ -177,6 +177,16 @@ RSpec.describe API::Helpers::Caching, :use_clean_rails_redis_caching do
5
.
times
{
perform
}
end
it
"handles nested cache calls"
do
nested_call
=
instance
.
cache_action
(
cache_key
,
**
kwargs
)
do
instance
.
cache_action
([
:nested
],
**
kwargs
)
do
expensive_thing
.
do_very_expensive_action
end
end
expect
(
nested_call
.
to_s
).
to
eq
(
subject
.
to_s
)
end
end
describe
"#cache_action_if"
do
...
...
spec/requests/api/branches_spec.rb
View file @
555bb5a0
...
...
@@ -20,7 +20,7 @@ RSpec.describe API::Branches do
stub_feature_flags
(
branch_list_keyset_pagination:
false
)
end
describe
"GET /projects/:id/repository/branches"
do
describe
"GET /projects/:id/repository/branches"
,
:use_clean_rails_redis_caching
do
let
(
:route
)
{
"/projects/
#{
project_id
}
/repository/branches"
}
shared_examples_for
'repository branches'
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