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
3c34a0b9
Commit
3c34a0b9
authored
Jul 18, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove old request store wrap
parent
3c7cb6ad
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
167 deletions
+0
-167
lib/gitlab/cache/request_store_wrap.rb
lib/gitlab/cache/request_store_wrap.rb
+0
-60
spec/lib/gitlab/cache/request_store_wrap_spec.rb
spec/lib/gitlab/cache/request_store_wrap_spec.rb
+0
-107
No files found.
lib/gitlab/cache/request_store_wrap.rb
deleted
100644 → 0
View file @
3c7cb6ad
module
Gitlab
module
Cache
# This module provides a simple way to cache values in RequestStore,
# and the cache key would be based on the class name, method name,
# customized instance level values, and arguments.
#
# A simple example:
#
# class UserAccess
# extend Gitlab::Cache::RequestStoreWrap
#
# request_store_wrap_key do
# [user.id, project.id]
# end
#
# request_store_wrap def can_push_to_branch?(ref)
# # ...
# end
# end
#
# This way, the result of `can_push_to_branch?` would be cached in
# `RequestStore.store` based on the cache key.
module
RequestStoreWrap
def
self
.
extended
(
klass
)
return
if
klass
<
self
extension
=
Module
.
new
klass
.
const_set
(
:RequestStoreWrapExtension
,
extension
)
klass
.
prepend
(
extension
)
end
def
request_store_wrap_key
(
&
block
)
if
block_given?
@request_store_wrap_key
=
block
else
@request_store_wrap_key
end
end
def
request_store_wrap
(
method_name
)
const_get
(
:RequestStoreWrapExtension
)
.
send
(
:define_method
,
method_name
)
do
|*
args
|
return
super
(
*
args
)
unless
RequestStore
.
active?
klass
=
self
.
class
key
=
[
klass
.
name
,
method_name
,
*
instance_exec
(
&
klass
.
request_store_wrap_key
),
*
args
].
join
(
':'
)
if
RequestStore
.
store
.
key?
(
key
)
RequestStore
.
store
[
key
]
else
RequestStore
.
store
[
key
]
=
super
(
*
args
)
end
end
end
end
end
end
spec/lib/gitlab/cache/request_store_wrap_spec.rb
deleted
100644 → 0
View file @
3c7cb6ad
require
'spec_helper'
describe
Gitlab
::
Cache
::
RequestStoreWrap
,
:request_store
do
class
ExpensiveAlgorithm
extend
Gitlab
::
Cache
::
RequestStoreWrap
attr_accessor
:id
,
:name
,
:result
def
initialize
(
id
,
name
,
result
)
self
.
id
=
id
self
.
name
=
name
self
.
result
=
result
end
request_store_wrap_key
do
[
id
,
name
]
end
request_store_wrap
def
compute
(
arg
)
result
<<
arg
end
request_store_wrap
def
repute
(
arg
)
result
<<
arg
end
end
let
(
:algorithm
)
{
ExpensiveAlgorithm
.
new
(
'id'
,
'name'
,
[])
}
context
'when RequestStore is active'
do
it
'does not compute twice for the same argument'
do
result
=
algorithm
.
compute
(
true
)
expect
(
result
).
to
eq
([
true
])
expect
(
algorithm
.
compute
(
true
)).
to
eq
(
result
)
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
it
'computes twice for the different argument'
do
algorithm
.
compute
(
true
)
result
=
algorithm
.
compute
(
false
)
expect
(
result
).
to
eq
([
true
,
false
])
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
it
'computes twice for the different keys, id'
do
algorithm
.
compute
(
true
)
algorithm
.
id
=
'ad'
result
=
algorithm
.
compute
(
true
)
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
it
'computes twice for the different keys, name'
do
algorithm
.
compute
(
true
)
algorithm
.
name
=
'same'
result
=
algorithm
.
compute
(
true
)
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
it
'computes twice for the different class name'
do
algorithm
.
compute
(
true
)
allow
(
ExpensiveAlgorithm
).
to
receive
(
:name
).
and_return
(
'CheapAlgo'
)
result
=
algorithm
.
compute
(
true
)
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
it
'computes twice for the different method'
do
algorithm
.
compute
(
true
)
result
=
algorithm
.
repute
(
true
)
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
it
'computes twice if RequestStore starts over'
do
algorithm
.
compute
(
true
)
RequestStore
.
end!
RequestStore
.
clear!
RequestStore
.
begin!
result
=
algorithm
.
compute
(
true
)
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
end
context
'when RequestStore is inactive'
do
before
do
RequestStore
.
end!
end
it
'computes twice even if everything is the same'
do
algorithm
.
compute
(
true
)
result
=
algorithm
.
compute
(
true
)
expect
(
result
).
to
eq
([
true
,
true
])
expect
(
algorithm
.
result
).
to
eq
(
result
)
end
end
end
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