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
44131d5c
Commit
44131d5c
authored
Aug 07, 2017
by
Sean McGivern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'perf.policy-runner-reduce-loops' into 'master'
DeclarativePolicy: reduce iterations of the step set See merge request !13352
parents
1f31c845
15bb6e1e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
5 deletions
+7
-5
runner.rb
lib/declarative_policy/runner.rb
+7
-5
No files found.
lib/declarative_policy/runner.rb
View file @
44131d5c
...
...
@@ -76,6 +76,8 @@ module DeclarativePolicy
@state
=
State
.
new
steps_by_score
do
|
step
,
score
|
return
if
!
debug
&&
@state
.
prevented?
passed
=
nil
case
step
.
action
when
:enable
then
...
...
@@ -93,10 +95,7 @@ module DeclarativePolicy
# been prevented.
unless
@state
.
prevented?
passed
=
step
.
pass?
if
passed
@state
.
prevent!
return
unless
debug
end
@state
.
prevent!
if
passed
end
debug
<<
inspect_step
(
step
,
score
,
passed
)
if
debug
...
...
@@ -141,13 +140,14 @@ module DeclarativePolicy
end
steps
=
Set
.
new
(
@steps
)
remaining_enablers
=
steps
.
count
{
|
s
|
s
.
enable?
}
loop
do
return
if
steps
.
empty?
# if the permission hasn't yet been enabled and we only have
# prevent steps left, we short-circuit the state here
@state
.
prevent!
if
!
@state
.
enabled?
&&
steps
.
all?
(
&
:prevent?
)
@state
.
prevent!
if
!
@state
.
enabled?
&&
remaining_enablers
==
0
lowest_score
=
Float
::
INFINITY
next_step
=
nil
...
...
@@ -162,6 +162,8 @@ module DeclarativePolicy
steps
.
delete
(
next_step
)
remaining_enablers
-=
1
if
next_step
.
enable?
yield
next_step
,
lowest_score
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