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
de9eca0a
Commit
de9eca0a
authored
Jul 06, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Rails.cache instead of Redis directly
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
e5a7d1da
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
31 deletions
+8
-31
lib/gitlab/performance_bar.rb
lib/gitlab/performance_bar.rb
+7
-22
spec/lib/gitlab/performance_bar_spec.rb
spec/lib/gitlab/performance_bar_spec.rb
+1
-9
No files found.
lib/gitlab/performance_bar.rb
View file @
de9eca0a
...
...
@@ -3,7 +3,7 @@ module Gitlab
ALLOWED_USER_IDS_KEY
=
'performance_bar_allowed_user_ids'
.
freeze
# The time (in seconds) after which a set of allowed user IDs is expired
# automatically.
ALLOWED_USER_IDS_TIME_TO_LIVE
=
10
.
minutes
.
to_i
ALLOWED_USER_IDS_TIME_TO_LIVE
=
10
.
minutes
def
self
.
enabled?
(
current_user
=
nil
)
Feature
.
enabled?
(
:gitlab_performance_bar
,
current_user
)
...
...
@@ -20,28 +20,13 @@ module Gitlab
end
def
self
.
allowed_user_ids
Gitlab
::
Redis
.
with
do
|
redis
|
if
redis
.
exists
(
cache_key
)
redis
.
smembers
(
cache_key
).
map
(
&
:to_i
)
else
group
=
Group
.
find_by_full_path
(
allowed_group_name
)
# Redis#sadd doesn't accept an empty array, but we still want to use
# Redis to let us know that no users are allowed, so we set the
# array to [-1] in this case.
user_ids
=
if
group
GroupMembersFinder
.
new
(
group
).
execute
.
pluck
(
:user_id
).
presence
||
[
-
1
]
else
[
-
1
]
end
redis
.
multi
do
redis
.
sadd
(
cache_key
,
user_ids
)
redis
.
expire
(
cache_key
,
ALLOWED_USER_IDS_TIME_TO_LIVE
)
end
Rails
.
cache
.
fetch
(
cache_key
,
expires_in:
ALLOWED_USER_IDS_TIME_TO_LIVE
)
do
group
=
Group
.
find_by_full_path
(
allowed_group_name
)
user_ids
if
group
GroupMembersFinder
.
new
(
group
).
execute
.
pluck
(
:user_id
)
else
[]
end
end
end
...
...
spec/lib/gitlab/performance_bar_spec.rb
View file @
de9eca0a
...
...
@@ -31,19 +31,11 @@ describe Gitlab::PerformanceBar do
described_class
.
allowed_user?
(
user
)
end
it
'caches the allowed user IDs in
Redis'
,
:redis
do
it
'caches the allowed user IDs in
cache'
,
:caching
do
expect
do
expect
(
described_class
.
allowed_user?
(
user
)).
to
be_truthy
end
.
not_to
exceed_query_limit
(
0
)
end
it
'caches the allowed user IDs for 10 minutes'
,
:redis
do
ttl_cached_user_ids
=
Gitlab
::
Redis
.
with
do
|
redis
|
redis
.
ttl
(
described_class
.
cache_key
)
end
expect
(
ttl_cached_user_ids
).
to
be
<=
10
.
minutes
end
end
describe
'.allowed_user?'
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