Reduce number of roles queries for the admin controller (#631)

This commit is contained in:
shawn-higgins1
2019-07-15 14:45:06 -04:00
committed by farhatahmad
parent 5a3ad3159c
commit 8c63f793a5
10 changed files with 24 additions and 20 deletions

View File

@ -106,7 +106,7 @@ module ApplicationHelper
# Returns the page that the logo redirects to when clicked on
def home_page
return root_path unless current_user
return admins_path if current_user.has_role? :super_admin
return admins_path if current_user.has_cached_role? :super_admin
current_user.main_room
end
end

View File

@ -37,7 +37,7 @@ module RoomsHelper
# Does not apply to admin or users that aren't signed in
# 15+ option is used as unlimited
return false if current_user&.has_role?(:admin) || limit == 15
return false if current_user&.has_cached_role?(:admin) || limit == 15
current_user.rooms.length >= limit
end
@ -46,7 +46,7 @@ module RoomsHelper
# Get how many rooms need to be deleted to reach allowed room number
limit = Setting.find_or_create_by!(provider: user_settings_provider).get_value("Room Limit").to_i
return false if current_user&.has_role?(:admin) || limit == 15
return false if current_user&.has_cached_role?(:admin) || limit == 15
@diff = current_user.rooms.count - limit
@diff.positive? && current_user.rooms.pluck(:id).index(room.id) + 1 > limit

View File

@ -61,7 +61,7 @@ module SessionsHelper
# Retrieves the current user.
def current_user
@current_user ||= User.find_by(id: session[:user_id])
@current_user ||= User.where(id: session[:user_id]).includes(:roles).first
end
def generate_checksum(user_domain, redirect_url, secret)

View File

@ -31,7 +31,7 @@ module ThemingHelper
# Returns the user's provider in the settings context
def user_settings_provider
if Rails.configuration.loadbalanced_configuration && current_user && !current_user&.has_role?(:super_admin)
if Rails.configuration.loadbalanced_configuration && current_user && !current_user&.has_cached_role?(:super_admin)
current_user.provider
elsif Rails.configuration.loadbalanced_configuration
@user_domain