Preload Event to avoid N+1s on the timeline
This commit is contained in:
@@ -9,6 +9,16 @@ class Event < ApplicationRecord
|
||||
has_many :webhook_deliveries, class_name: "Webhook::Delivery", dependent: :delete_all
|
||||
|
||||
scope :chronologically, -> { order created_at: :asc, id: :desc }
|
||||
scope :preloaded, -> {
|
||||
includes(:creator, :board, {
|
||||
eventable: [
|
||||
:goldness, :closure, :image_attachment,
|
||||
{ rich_text_body: :embeds_attachments },
|
||||
{ rich_text_description: :embeds_attachments },
|
||||
{ card: [:goldness, :closure, :image_attachment] }
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
after_create -> { eventable.event_was_created(self) }
|
||||
after_create_commit :dispatch_webhooks
|
||||
|
||||
@@ -71,7 +71,7 @@ class User::DayTimeline
|
||||
|
||||
def timelineable_events
|
||||
Event
|
||||
.includes(:creator, :board, :eventable)
|
||||
.preloaded
|
||||
.where(board: boards)
|
||||
.where(action: TIMELINEABLE_ACTIONS)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user