Merge pull request #2406 from basecamp/search-content-limit

Only index up to 32KB of search content
This commit is contained in:
Kevin McConnell
2026-01-21 10:05:24 +00:00
committed by GitHub
2 changed files with 25 additions and 1 deletions
+7 -1
View File
@@ -1,6 +1,8 @@
module Searchable
extend ActiveSupport::Concern
SEARCH_CONTENT_LIMIT = 32.kilobytes
included do
after_create_commit :create_in_search_index
after_update_commit :update_in_search_index
@@ -32,11 +34,15 @@ module Searchable
card_id: search_card_id,
board_id: search_board_id,
title: search_title,
content: search_content,
content: search_record_content,
created_at: created_at
}
end
def search_record_content
search_content&.truncate_bytes(SEARCH_CONTENT_LIMIT, omission: "")
end
def search_record_class
Search::Record.for(account_id)
end
+18
View File
@@ -32,6 +32,24 @@ class Card::SearchableTest < ActiveSupport::TestCase
assert_not_includes results, card_in_other_board
end
test "search content is truncated to a reasonable limit" do
search_record_class = Search::Record.for(@user.account_id)
# Create a card with unreasonably long content
long_content = "asdf " * Searchable::SEARCH_CONTENT_LIMIT
card = @board.cards.create!(title: "Card with long description", creator: @user)
card.description = ActionText::Content.new(long_content)
card.save!
# Check if was indexed
results = Card.mentioning("asdf", user: @user)
assert_includes results, card
# Check the content length was within the limit
search_record = search_record_class.find_by(searchable_type: "Card", searchable_id: card.id)
assert search_record.content.bytesize <= Searchable::SEARCH_CONTENT_LIMIT
end
test "deleting card removes search record and FTS entry" do
search_record_class = Search::Record.for(@user.account_id)
card = @board.cards.create!(title: "Card to delete", creator: @user)