diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-07-04 12:48:45 +0300 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-07-04 16:56:41 +0300 |
commit | 216bf78fd154005cbf8ec447bfa23f77f6b26775 (patch) | |
tree | 3f2d89b3934865968f39adacd71e90f1bc0868ba /lib/gitlab/user_access.rb | |
parent | 28553dbc05989b698777ee085aa2a357ffe576d2 (diff) |
Introduce Gitlab::Cache::RequestStoreWrap
So that we cache the result of UserAccess#can_push_or_merge_to_branch?
in RequestStore, avoiding querying ProtectedBranch over and over for
the list of pipelines (i.e. in PipelineSerializer)
I don't think this is ideal because I don't like the idea of
RequestStore in general, but this is the easiest way to cache it
without changing the architecture. In the future we should cache
more explicitly rather than this kind of global store.
Diffstat (limited to 'lib/gitlab/user_access.rb')
-rw-r--r-- | lib/gitlab/user_access.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/gitlab/user_access.rb b/lib/gitlab/user_access.rb index bb05c474fa2..d8b043f5021 100644 --- a/lib/gitlab/user_access.rb +++ b/lib/gitlab/user_access.rb @@ -1,5 +1,11 @@ module Gitlab class UserAccess + extend Gitlab::Cache::RequestStoreWrap + + request_store_wrap_key do + [user&.id, project&.id] + end + attr_reader :user, :project def initialize(user, project: nil) @@ -52,7 +58,7 @@ module Gitlab can_push_to_branch?(ref) || can_merge_to_branch?(ref) end - def can_push_to_branch?(ref) + request_store_wrap def can_push_to_branch?(ref) return false unless can_access_git? if ProtectedBranch.protected?(project, ref) @@ -64,7 +70,7 @@ module Gitlab end end - def can_merge_to_branch?(ref) + request_store_wrap def can_merge_to_branch?(ref) return false unless can_access_git? if ProtectedBranch.protected?(project, ref) |