mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-05-25 19:48:44 +09:00
Merge pull request #53 from raulpopadineti/speed-improvements-1
Speed up room's initial load by reducing N+1 queries
This commit is contained in:
@@ -32,7 +32,7 @@ class RoomsController < ApplicationController
|
||||
end
|
||||
|
||||
def find_messages
|
||||
messages = @room.messages.with_creator
|
||||
messages = @room.messages.with_creator.with_attachment_details.with_boosts
|
||||
|
||||
if show_first_message = messages.find_by(id: params[:message_id])
|
||||
@messages = messages.page_around(show_first_message)
|
||||
|
||||
@@ -12,7 +12,13 @@ class Message < ApplicationRecord
|
||||
after_create_commit -> { room.receive(self) }
|
||||
|
||||
scope :ordered, -> { order(:created_at) }
|
||||
scope :with_creator, -> { includes(:creator) }
|
||||
scope :with_creator, -> { preload(creator: :avatar_attachment) }
|
||||
scope :with_attachment_details, -> {
|
||||
with_rich_text_body_and_embeds
|
||||
with_attached_attachment
|
||||
.includes(attachment_blob: :variant_records)
|
||||
}
|
||||
scope :with_boosts, -> { includes(boosts: :booster) }
|
||||
|
||||
def plain_text_body
|
||||
body.to_plain_text.presence || attachment&.filename&.to_s || ""
|
||||
|
||||
Reference in New Issue
Block a user