Only index up to 32KB of search content
To prevent overflowing the columns in the search index tables (and also just to avoid creating massive indexes), let's limit the searchable content to the first 32KB.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user