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
ffc5b29b
Commit
ffc5b29b
authored
Jul 18, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Follow feedback on the merge request
parent
042cf15b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
19 deletions
+15
-19
app/models/commit.rb
app/models/commit.rb
+1
-1
changelogs/unreleased/request-store-wrap.yml
changelogs/unreleased/request-store-wrap.yml
+1
-1
lib/gitlab/cache/request_cache.rb
lib/gitlab/cache/request_cache.rb
+10
-14
lib/gitlab/user_access.rb
lib/gitlab/user_access.rb
+1
-1
spec/lib/gitlab/cache/request_cache_spec.rb
spec/lib/gitlab/cache/request_cache_spec.rb
+2
-2
No files found.
app/models/commit.rb
View file @
ffc5b29b
class
Commit
extend
ActiveModel
::
Naming
extend
Gitlab
::
Cache
::
Request
StoreWrap
extend
Gitlab
::
Cache
::
Request
Cache
include
ActiveModel
::
Conversion
include
Noteable
...
...
changelogs/unreleased/request-store-wrap.yml
View file @
ffc5b29b
---
title
:
Add Request
StoreWrap
which makes caching with RequestStore easier
title
:
Add Request
Cache
which makes caching with RequestStore easier
merge_request
:
12920
author
:
lib/gitlab/cache/request_
store_wrap
.rb
→
lib/gitlab/cache/request_
cache
.rb
View file @
ffc5b29b
...
...
@@ -8,7 +8,7 @@ module Gitlab
# A simple example:
#
# class UserAccess
# extend Gitlab::Cache::Request
StoreWrap
# extend Gitlab::Cache::Request
Cache
#
# request_store_wrap_key do
# [user&.id, project&.id]
...
...
@@ -26,7 +26,7 @@ module Gitlab
# Here's another example using customized method level values:
#
# class Commit
# extend Gitlab::Cache::Request
StoreWrap
# extend Gitlab::Cache::Request
Cache
#
# def author
# User.find_by_any_email(author_email.downcase)
...
...
@@ -36,12 +36,12 @@ module Gitlab
#
# So that we could have different strategies for different methods
#
module
Request
StoreWrap
module
Request
Cache
def
self
.
extended
(
klass
)
return
if
klass
<
self
extension
=
Module
.
new
klass
.
const_set
(
:Request
StoreWrap
Extension
,
extension
)
klass
.
const_set
(
:Request
Cache
Extension
,
extension
)
klass
.
prepend
(
extension
)
end
...
...
@@ -54,30 +54,26 @@ module Gitlab
end
def
request_store_wrap
(
method_name
,
&
method_key_block
)
const_get
(
:RequestStoreWrapExtension
).
module_eval
do
const_get
(
:RequestCacheExtension
).
module_eval
do
cache_key_method_name
=
"
#{
method_name
}
_cache_key"
define_method
(
method_name
)
do
|*
args
|
store
=
if
RequestStore
.
active?
RequestStore
.
store
else
ivar_name
=
# ! and ? cannot be used as ivar name
"@
#{
method_name
.
to_s
.
tr
(
'!'
,
"
\u
2605"
).
tr
(
'?'
,
"
\u
2606"
)
}
"
"@
cache_
#{
method_name
.
to_s
.
tr
(
'!?'
,
"
\u
2605
\u
2606"
)
}
"
instance_variable_get
(
ivar_name
)
||
instance_variable_set
(
ivar_name
,
{})
end
key
=
send
(
"
#{
method_name
}
_cache_key"
,
args
)
key
=
__send__
(
cache_key_method_name
,
args
)
if
store
.
key?
(
key
)
store
[
key
]
else
store
[
key
]
=
super
(
*
args
)
end
store
.
fetch
(
key
)
{
store
[
key
]
=
super
(
*
args
)
}
end
cache_key_method_name
=
"
#{
method_name
}
_cache_key"
define_method
(
cache_key_method_name
)
do
|
args
|
klass
=
self
.
class
...
...
lib/gitlab/user_access.rb
View file @
ffc5b29b
module
Gitlab
class
UserAccess
extend
Gitlab
::
Cache
::
Request
StoreWrap
extend
Gitlab
::
Cache
::
Request
Cache
request_store_wrap_key
do
[
user
&
.
id
,
project
&
.
id
]
...
...
spec/lib/gitlab/cache/request_
store_wrap
_spec.rb
→
spec/lib/gitlab/cache/request_
cache
_spec.rb
View file @
ffc5b29b
require
'spec_helper'
describe
Gitlab
::
Cache
::
Request
StoreWrap
,
:request_store
do
describe
Gitlab
::
Cache
::
Request
Cache
,
:request_store
do
let
(
:klass
)
do
Class
.
new
do
extend
Gitlab
::
Cache
::
Request
StoreWrap
extend
Gitlab
::
Cache
::
Request
Cache
attr_accessor
:id
,
:name
,
:result
,
:extra
...
...
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