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
Jérome Perrin
gitlab-ce
Commits
b531616e
Commit
b531616e
authored
Jun 28, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache PerformanceBar data using RequestStore
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
186048a4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
18 deletions
+33
-18
config/initializers/1_settings.rb
config/initializers/1_settings.rb
+1
-1
lib/gitlab/performance_bar.rb
lib/gitlab/performance_bar.rb
+22
-7
spec/lib/gitlab/performance_bar_spec.rb
spec/lib/gitlab/performance_bar_spec.rb
+10
-10
No files found.
config/initializers/1_settings.rb
View file @
b531616e
...
...
@@ -489,7 +489,7 @@ Settings.gitaly['enabled'] = true if Settings.gitaly['enabled'].nil?
# Performance bar
#
Settings
[
'performance_bar'
]
||=
Settingslogic
.
new
({})
Settings
.
performance_bar
[
'allowed_group'
]
=
'gitlab-org'
if
Settings
.
performance_bar
[
'allowed_group'
].
nil?
Settings
.
performance_bar
[
'allowed_group'
]
||=
nil
#
# Webpack settings
...
...
lib/gitlab/performance_bar.rb
View file @
b531616e
...
...
@@ -5,19 +5,34 @@ module Gitlab
end
def
self
.
allowed_actor?
(
actor
)
group
=
allowed_group
return
false
unless
actor
&
.
is_a?
(
User
)
&&
group
return
false
unless
actor
.
thing
&
.
is_a?
(
User
)
&&
allowed_group
GroupMembersFinder
.
new
(
group
)
.
execute
.
where
(
user_id:
actor
.
id
)
.
any?
if
RequestStore
.
active?
RequestStore
.
fetch
(
'performance_bar:user_member_of_allowed_group'
)
do
user_member_of_allowed_group?
(
actor
.
thing
)
end
else
user_member_of_allowed_group?
(
actor
.
thing
)
end
end
def
self
.
allowed_group
return
nil
unless
Gitlab
.
config
.
performance_bar
.
allowed_group
Group
.
by_path
(
Gitlab
.
config
.
performance_bar
.
allowed_group
)
if
RequestStore
.
active?
RequestStore
.
fetch
(
'performance_bar:allowed_group'
)
do
Group
.
by_path
(
Gitlab
.
config
.
performance_bar
.
allowed_group
)
end
else
Group
.
by_path
(
Gitlab
.
config
.
performance_bar
.
allowed_group
)
end
end
def
self
.
user_member_of_allowed_group?
(
user
)
GroupMembersFinder
.
new
(
allowed_group
)
.
execute
.
where
(
user_id:
user
.
id
)
.
any?
end
end
end
spec/lib/gitlab/performance_bar_spec.rb
View file @
b531616e
...
...
@@ -2,38 +2,38 @@ require 'spec_helper'
describe
Gitlab
::
PerformanceBar
do
describe
'.enabled?'
do
it
'returns false when given
use
r is nil'
do
it
'returns false when given
acto
r is nil'
do
expect
(
described_class
.
enabled?
(
nil
)).
to
be_falsy
end
it
'returns false when feature is disabled'
do
user
=
double
(
'use
r'
)
actor
=
double
(
'acto
r'
)
expect
(
Feature
).
to
receive
(
:enabled?
)
.
with
(
:gitlab_performance_bar
,
use
r
).
and_return
(
false
)
.
with
(
:gitlab_performance_bar
,
acto
r
).
and_return
(
false
)
expect
(
described_class
.
enabled?
(
use
r
)).
to
be_falsy
expect
(
described_class
.
enabled?
(
acto
r
)).
to
be_falsy
end
it
'returns true when feature is enabled'
do
user
=
double
(
'use
r'
)
actor
=
double
(
'acto
r'
)
expect
(
Feature
).
to
receive
(
:enabled?
)
.
with
(
:gitlab_performance_bar
,
use
r
).
and_return
(
true
)
.
with
(
:gitlab_performance_bar
,
acto
r
).
and_return
(
true
)
expect
(
described_class
.
enabled?
(
use
r
)).
to
be_truthy
expect
(
described_class
.
enabled?
(
acto
r
)).
to
be_truthy
end
end
describe
'.allowed_actor?'
do
it
'returns false when given actor is not a User'
do
actor
=
double
actor
=
double
(
'actor'
,
thing:
double
)
expect
(
described_class
.
allowed_actor?
(
actor
)).
to
be_falsy
end
context
'when given actor is a User'
do
let
(
:actor
)
{
create
(
:user
)
}
let
(
:actor
)
{
double
(
'actor'
,
thing:
create
(
:user
)
)
}
before
do
stub_performance_bar_setting
(
allowed_group:
'my-group'
)
...
...
@@ -56,7 +56,7 @@ describe Gitlab::PerformanceBar do
context
'when user is a member of the allowed group'
do
before
do
my_group
.
add_developer
(
actor
)
my_group
.
add_developer
(
actor
.
thing
)
end
it
'returns true'
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