Use role caching for Rolify to avoid N+1 queries

Resolves #2018

See https://github.com/RolifyCommunity/rolify#cached-roles-to-avoid-n1-issue
This commit is contained in:
James Mason 2018-03-28 17:31:18 -07:00
parent 30ba7b133b
commit 98defe2d0f
13 changed files with 44 additions and 35 deletions

View file

@ -6,7 +6,7 @@ module Admin
def index
@conferences_with_role = current_user.is_admin? ? Conference.pluck(:short_title) : Conference.with_role([:organizer, :cfp, :info_desk], current_user).pluck(:short_title)
if current_user.has_role? :organization_admin, :any
if current_user.has_cached_role? :organization_admin, :any
@conferences_with_role = Organization.with_role('organization_admin', current_user).map { |org| org.conferences.pluck :short_title }.flatten
end
@conferences_with_role.uniq!