Skip to content

Commit

Permalink
Cache User#is_admin? & User#is_staff?
Browse files Browse the repository at this point in the history
is_admin? is called in many places, often 3 and more times
per action.

Co-authored-by: Ana María Martínez Gómez <ammartinez@suse.de>
  • Loading branch information
coolo and Ana06 committed Dec 17, 2018
1 parent 9559d3d commit 9653de6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/api/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,13 @@ def update_user_info_from_proxy_env(env)
#####################

def is_admin?
roles.where(title: 'Admin').exists?
return @is_admin unless @is_admin.nil?
@is_admin = roles.where(title: 'Admin').exists?
end

def is_staff?
roles.where(title: 'Staff').exists?
return @is_staff unless @is_staff.nil?
@is_staff = roles.where(title: 'Staff').exists?
end

def is_nobody?
Expand Down

0 comments on commit 9653de6

Please sign in to comment.