BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
e1ffd6a2
Unverified
Commit
e1ffd6a2
authored
May 31, 2018
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use RequestStore to memoize Flipper features so that memoized values are cleared between requests
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
c5f89e5b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
1 deletion
+32
-1
feature.rb
lib/feature.rb
+8
-1
feature_spec.rb
spec/lib/feature_spec.rb
+24
-0
No files found.
lib/feature.rb
View file @
e1ffd6a2
...
@@ -63,7 +63,14 @@ class Feature
...
@@ -63,7 +63,14 @@ class Feature
end
end
def
flipper
def
flipper
Thread
.
current
[
:flipper
]
||=
if
RequestStore
.
active?
RequestStore
[
:flipper
]
||=
build_flipper_instance
else
@flipper
||=
build_flipper_instance
end
end
def
build_flipper_instance
Flipper
.
new
(
flipper_adapter
).
tap
{
|
flip
|
flip
.
memoize
=
true
}
Flipper
.
new
(
flipper_adapter
).
tap
{
|
flip
|
flip
.
memoize
=
true
}
end
end
...
...
spec/lib/feature_spec.rb
View file @
e1ffd6a2
...
@@ -64,4 +64,28 @@ describe Feature do
...
@@ -64,4 +64,28 @@ describe Feature do
expect
(
described_class
.
all
).
to
eq
(
features
.
to_a
)
expect
(
described_class
.
all
).
to
eq
(
features
.
to_a
)
end
end
end
end
describe
'.flipper'
do
shared_examples
'a memoized Flipper instance'
do
it
'memoizes the Flipper instance'
do
expect
(
Flipper
).
to
receive
(
:new
).
once
.
and_call_original
2
.
times
do
described_class
.
flipper
end
end
end
context
'when request store is inactive'
do
before
do
described_class
.
instance_variable_set
(
:@flipper
,
nil
)
end
it_behaves_like
'a memoized Flipper instance'
end
context
'when request store is inactive'
,
:request_store
do
it_behaves_like
'a memoized Flipper instance'
end
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