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:
parent
30ba7b133b
commit
98defe2d0f
13 changed files with 44 additions and 35 deletions
|
|
@ -6,6 +6,9 @@ end
|
|||
|
||||
class User < ApplicationRecord
|
||||
rolify
|
||||
# prevent N+1 queries with has_cached_role? by preloading roles *always*
|
||||
default_scope { preload(:roles) }
|
||||
|
||||
has_many :physical_tickets, through: :ticket_purchases do
|
||||
def by_conference(conference)
|
||||
where('ticket_purchases.conference_id = ?', conference)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue