1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

avoid N+1 for users list

This commit is contained in:
Peng DU 2016-06-24 18:43:22 +02:00
parent d64e8a291b
commit 0bb4665b4a
2 changed files with 2 additions and 2 deletions

View File

@ -3,7 +3,7 @@ class API::AdminsController < API::ApiController
def index
authorize :admin
@admins = User.admins
@admins = User.includes(profile: [:user_avatar]).admins
end
def create

View File

@ -169,7 +169,7 @@ class API::MembersController < API::ApiController
order_key = 'users.id'
end
@members = User.includes(:profile, :group)
@members = User.includes(:profile, :group, :subscriptions)
.joins(:profile, :group, :roles, 'LEFT JOIN "subscriptions" ON "subscriptions"."user_id" = "users"."id" LEFT JOIN "plans" ON "plans"."id" = "subscriptions"."plan_id"')
.where("users.is_active = 'true' AND roles.name = 'member'")
.order("#{order_key} #{direction}")