summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhttp://jneen.net/ <jneen@jneen.net>2017-07-17 10:47:27 -0700
committerhttp://jneen.net/ <jneen@jneen.net>2017-07-17 14:38:48 -0700
commitfcd3e5d4777efb4b6db2de08347e4db603e1dea2 (patch)
tree292f8259a3c012bb83d10143d0147f881de550c0
parent45e9d2879122d2aea9494241fac0bd8bf7096446 (diff)
downloadgitlab-ce-fcd3e5d4777efb4b6db2de08347e4db603e1dea2.tar.gz
cache the cache key...perf/policy-class-cache
-rw-r--r--lib/declarative_policy/condition.rb15
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/declarative_policy/condition.rb b/lib/declarative_policy/condition.rb
index 9d7cf6b9726..51c4a8b2bbe 100644
--- a/lib/declarative_policy/condition.rb
+++ b/lib/declarative_policy/condition.rb
@@ -82,13 +82,14 @@ module DeclarativePolicy
# depending on the scope, we may cache only by the user or only by
# the subject, resulting in sharing across different policy objects.
def cache_key
- case @condition.scope
- when :normal then "/dp/condition/#{@condition.key}/#{user_key},#{subject_key}"
- when :user then "/dp/condition/#{@condition.key}/#{user_key}"
- when :subject then "/dp/condition/#{@condition.key}/#{subject_key}"
- when :global then "/dp/condition/#{@condition.key}"
- else raise 'invalid scope'
- end
+ @cache_key ||=
+ case @condition.scope
+ when :normal then "/dp/condition/#{@condition.key}/#{user_key},#{subject_key}"
+ when :user then "/dp/condition/#{@condition.key}/#{user_key}"
+ when :subject then "/dp/condition/#{@condition.key}/#{subject_key}"
+ when :global then "/dp/condition/#{@condition.key}"
+ else raise 'invalid scope'
+ end
end
def user_key