diff options
author | http://jneen.net/ <jneen@jneen.net> | 2017-08-07 12:36:13 -0700 |
---|---|---|
committer | http://jneen.net/ <jneen@jneen.net> | 2017-08-07 12:36:13 -0700 |
commit | 8a167554a9dae4ab10f5a56124a598227bf5e3ed (patch) | |
tree | 22f3377fc294e31639e8c29d4a230e7ede4f5f15 /lib/declarative_policy | |
parent | bc648ae5d225b3b76cc3105681e2f404a5918f85 (diff) | |
download | gitlab-ce-8a167554a9dae4ab10f5a56124a598227bf5e3ed.tar.gz |
reduce iterations by keeping a count of remaining enablers
rather than iterating the whole remaining step set with
.all?(&:prevent?)
Diffstat (limited to 'lib/declarative_policy')
-rw-r--r-- | lib/declarative_policy/runner.rb | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/declarative_policy/runner.rb b/lib/declarative_policy/runner.rb index b5c615da4e3..1122b9e42ec 100644 --- a/lib/declarative_policy/runner.rb +++ b/lib/declarative_policy/runner.rb @@ -141,13 +141,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 +163,8 @@ module DeclarativePolicy steps.delete(next_step) + remaining_enablers -= 1 if next_step.enable? + yield next_step, lowest_score end end |