forked from External/greenlight
Refactored code to reduce number of database queries (#960)
This commit is contained in:
@ -292,11 +292,11 @@ class AdminsController < ApplicationController
|
||||
private
|
||||
|
||||
def find_user
|
||||
@user = User.where(uid: params[:user_uid]).includes(:roles).first
|
||||
@user = User.find_by(uid: params[:user_uid])
|
||||
end
|
||||
|
||||
def find_deleted_user
|
||||
@user = User.deleted.where(uid: params[:user_uid]).includes(:roles).first
|
||||
@user = User.deleted.find_by(uid: params[:user_uid])
|
||||
end
|
||||
|
||||
# Verifies that admin is an administrator of the user in the action
|
||||
|
@ -29,7 +29,7 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
# Retrieves the current user.
|
||||
def current_user
|
||||
@current_user ||= User.where(id: session[:user_id]).includes(:roles).first
|
||||
@current_user ||= User.includes(:roles, :main_room).find_by(id: session[:user_id])
|
||||
|
||||
if Rails.configuration.loadbalanced_configuration
|
||||
if @current_user && !@current_user.has_role?(:super_admin) &&
|
||||
@ -67,7 +67,7 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
# Sets the settinfs variable
|
||||
def set_user_settings
|
||||
@settings = Setting.find_or_create_by(provider: @user_domain)
|
||||
@settings = Setting.includes(:features).find_or_create_by(provider: @user_domain)
|
||||
end
|
||||
|
||||
# Redirects the user to a Maintenance page if turned on
|
||||
|
@ -25,11 +25,11 @@ module Populator
|
||||
|
||||
initial_user = case @tab
|
||||
when "active"
|
||||
User.without_role(:pending).without_role(:denied)
|
||||
User.includes(:roles).without_role(:pending).without_role(:denied)
|
||||
when "deleted"
|
||||
User.deleted
|
||||
User.includes(:roles).deleted
|
||||
else
|
||||
User
|
||||
User.includes(:roles)
|
||||
end
|
||||
|
||||
current_role = Role.find_by(name: @tab, provider: @user_domain) if @tab == "pending" || @tab == "denied"
|
||||
@ -57,7 +57,7 @@ module Populator
|
||||
.admins_search(@search)
|
||||
.admins_order(@order_column, @order_direction)
|
||||
else
|
||||
Room.all.admins_search(@search).admins_order(@order_column, @order_direction)
|
||||
Room.includes(:owner).all.admins_search(@search).admins_order(@order_column, @order_direction)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -293,7 +293,7 @@ class RoomsController < ApplicationController
|
||||
|
||||
# Find the room from the uid.
|
||||
def find_room
|
||||
@room = Room.find_by!(uid: params[:room_uid])
|
||||
@room = Room.includes(:owner).find_by!(uid: params[:room_uid])
|
||||
end
|
||||
|
||||
# Ensure the user either owns the room or is an admin of the room owner or the room is shared with him
|
||||
|
@ -190,7 +190,7 @@ class UsersController < ApplicationController
|
||||
private
|
||||
|
||||
def find_user
|
||||
@user = User.where(uid: params[:user_uid]).includes(:roles).first
|
||||
@user = User.find_by(uid: params[:user_uid])
|
||||
end
|
||||
|
||||
# Verify that GreenLight is configured to allow user signup.
|
||||
|
Reference in New Issue
Block a user