Render the boosts a message has preloaded instead of querying them again

Pages of messages load them with_presentation, which preloads each
message's boosts with their boosters and avatars, but the boosts partial
asked for message.boosts.ordered: a new query for every message, and the
preloaded boosts went unused. Sort the preloaded boosts in Ruby. The
boosts frame, whose message comes without them, still queries them in
order with their boosters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0142qgjggdJ2KDdGk7RF9Xm9
This commit is contained in:
Marcello Costagliola
2026-10-05 17:17:29 +02:00
parent c761763c8c
commit 20275e1fa7
2 changed files with 15 additions and 1 deletions
+14
View File
@@ -53,6 +53,20 @@ class MessagesCachingTest < ActionDispatch::IntegrationTest
end
end
test "messages render their preloaded boosts in order without querying them again" do
earlier = messages(:fourth).boosts.create! booster: users(:jason), content: "🥇", created_at: 1.day.ago
in_order = [ dom_id(earlier), dom_id(boosts(:fourth_by_bender)) ]
assert_no_queries_match(/ORDER BY "boosts"/) do
get room_messages_url(rooms(:watercooler))
end
assert_response :success
assert_equal in_order, css_select("##{dom_id(messages(:fourth), :boosts)} .boost").map { it["id"] }
get message_boosts_url(messages(:fourth))
assert_equal in_order, css_select("##{dom_id(messages(:fourth), :boosts)} .boost").map { it["id"] }
end
private
def with_memory_cache
old_cache = Rails.cache