Merge pull request #304 from namespaceMarcello/search-newest-matches-by-rowid

Read the newest search matches off the index instead of sorting them all
This commit is contained in:
Stanko Krtalić
2026-10-05 16:59:44 +02:00
committed by GitHub
3 changed files with 24 additions and 1 deletions
+15
View File
@@ -20,6 +20,21 @@ class Message::SearchableTest < ActiveSupport::TestCase
assert_equal messages, rooms(:designers).messages.search("cat")
end
test "the last page of matches holds the newest ones, read off the index without sorting every match" do
messages = [ "first cat", "second cat", "third cat" ].map do |body|
rooms(:designers).messages.create! body: body, client_message_id: body, creator: users(:david)
end
queries = []
collect = ->(*, payload) { queries << payload[:sql] if payload[:sql].include?("message_search_index") }
page = ActiveSupport::Notifications.subscribed(collect, "sql.active_record") do
rooms(:designers).messages.search("cat").last_page_of_matches(2)
end
assert_equal messages.last(2), page
assert_no_match(/TEMP B-TREE/, Message.connection.select_rows("EXPLAIN QUERY PLAN #{queries.sole}").map(&:last).join(" | "))
end
test "rich text body is converted to plain text for indexing" do
message = rooms(:designers).messages.create! body: "<span>My hovercraft is full of eels</span>", client_message_id: "earth", creator: users(:david)