From cf0ba58d8d4e654c2b0faa8883df37099aab1277 Mon Sep 17 00:00:00 2001 From: Marcello Costagliola Date: Mon, 5 Oct 2026 01:03:39 +0200 Subject: [PATCH 1/2] Check for a second page of messages without counting the room The original room shows its welcome box until it holds more than a page of messages, and paged? answered that with a COUNT(*) over every message in the room on each visit. Asking whether there is a row past the first page answers the same question while reading at most a page of index entries. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01NuTtwJKhb77Dv7EQqv2C3C --- app/models/message/pagination.rb | 2 +- test/models/message_test.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/message/pagination.rb b/app/models/message/pagination.rb index 3be7983..0e7690b 100644 --- a/app/models/message/pagination.rb +++ b/app/models/message/pagination.rb @@ -49,7 +49,7 @@ module Message::Pagination end def paged? - count > PAGE_SIZE + offset(PAGE_SIZE).exists? end end end diff --git a/test/models/message_test.rb b/test/models/message_test.rb index 5ffecea..df3a694 100644 --- a/test/models/message_test.rb +++ b/test/models/message_test.rb @@ -65,6 +65,18 @@ class MessageTest < ActiveSupport::TestCase assert_equal room.messages.ordered.first(Message::Pagination::PAGE_SIZE).map(&:id), room.messages.first_page.map(&:id) end + test "paged? tells whether a room has more than a page of messages without counting them all" do + room = Rooms::Closed.create!(name: "Paging", creator: users(:david)) + Message.insert_all Array.new(Message::Pagination::PAGE_SIZE) { |i| { room_id: room.id, creator_id: users(:david).id, client_message_id: "paging-#{i}" } } + + assert_no_queries_match(/COUNT/i) do + assert_not room.messages.paged? + + Message.insert_all [ { room_id: room.id, creator_id: users(:david).id, client_message_id: "paging-next" } ] + assert room.messages.paged? + end + end + private def create_new_message_in(room) room.messages.create!(creator: users(:jason), body: "Hello", client_message_id: "123") From 259c06bea107b713ae1b567337c0d30bc55979c3 Mon Sep 17 00:00:00 2001 From: "Stanko K.R." Date: Mon, 5 Oct 2026 16:30:18 +0200 Subject: [PATCH 2/2] Remove trailing whitespace --- test/models/message_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/models/message_test.rb b/test/models/message_test.rb index 05fc9b5..a5b73f0 100644 --- a/test/models/message_test.rb +++ b/test/models/message_test.rb @@ -76,7 +76,7 @@ class MessageTest < ActiveSupport::TestCase assert room.messages.paged? end end - + test "search reads quotes and operator words in the query as text" do message = rooms(:designers).messages.create!(body: "Say hi, NOT bye", client_message_id: "quoted", creator: users(:david))