Files
fizzy/test/models/search_test.rb
T
Donal McBreen 3aa4a1a562 Shard the search index into 16 tables
Create search_index_0 to search_index_15 tables and shard each index by
account id. MySQL has no ability to pre-filter fulltext indexes by
another field so this is the best bet for improving performance.

Each fulltest index internally creates 11 sub tables (see
https://dev.mysql.com/doc/refman/8.4/en/innodb-fulltext-index.html) so
actually we have 192 tables in total here.

The search_index table name is generated dynamically based on the
account_id.
2025-11-17 09:12:17 -05:00

49 lines
2.0 KiB
Ruby

require "test_helper"
class SearchTest < ActiveSupport::TestCase
self.use_transactional_tests = false
setup do
16.times { |i| ActiveRecord::Base.connection.execute "DELETE FROM search_index_#{i}" }
Account.find_by(name: "Search Test")&.destroy
@account = Account.create!(name: "Search Test")
@user = User.create!(name: "Test User", account: @account)
@board = Board.create!(name: "Test Board", account: @account, creator: @user)
Current.account = @account
end
teardown do
16.times { |i| ActiveRecord::Base.connection.execute "DELETE FROM search_index_#{i}" }
Account.find_by(name: "Search Test")&.destroy
end
test "search" do
# Search cards and comments
card = @board.cards.create!(title: "layout design", creator: @user)
comment_card = @board.cards.create!(title: "Some card", creator: @user)
comment_card.comments.create!(body: "overflowing text", creator: @user)
results = Search.new(@user, "layout").results
assert results.find { |it| it.card_id == card.id }
results = Search.new(@user, "overflowing").results
assert results.find { |it| it.card_id == comment_card.id && it.comment_id.present? }
# Don't include inaccessible boards
other_user = User.create!(name: "Other User", account: @account)
inaccessible_board = Board.create!(name: "Inaccessible Board", account: @account, creator: other_user)
accessible_card = @board.cards.create!(title: "searchable content", creator: @user)
inaccessible_card = inaccessible_board.cards.create!(title: "searchable content", creator: other_user)
results = Search.new(@user, "searchable").results
assert results.find { |it| it.card_id == accessible_card.id }
assert_not results.find { |it| it.card_id == inaccessible_card.id }
# Empty board_ids returns no results
user_without_access = User.create!(name: "No Access User", account: @account)
results = Search.new(user_without_access, "anything").results
assert_empty results
end
end