Preload Event to avoid N+1s on the timeline

This commit is contained in:
Mike Dalessio
2025-11-27 11:27:10 -05:00
parent 79c9ea2ce1
commit 0ab3aaca72
2 changed files with 11 additions and 1 deletions
+10
View File
@@ -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
+1 -1
View File
@@ -71,7 +71,7 @@ class User::DayTimeline
def timelineable_events
Event
.includes(:creator, :board, :eventable)
.preloaded
.where(board: boards)
.where(action: TIMELINEABLE_ACTIONS)
end