Remove Search::Record.for_account

Instead we'll compute the table name dynamically based on
Current.account where needed. Also we'll prevent searchable records
from being saved if Current.account is not set, otherwise the after
commit callbacks will fail.
This commit is contained in:
Donal McBreen
2025-11-21 12:06:32 +00:00
parent 4008819390
commit 01d16f96d4
8 changed files with 48 additions and 28 deletions
+9 -2
View File
@@ -2,17 +2,24 @@ namespace :search do
desc "Reindex all cards and comments in the search index"
task reindex: :environment do
puts "Clearing search records..."
Search::Record::Trilogy::SHARD_COUNT.times do |shard_id|
ActiveRecord::Base.connection.execute("DELETE FROM search_records_#{shard_id}")
if ActiveRecord::Base.connection.adapter_name == "SQLite"
ActiveRecord::Base.connection.execute("DELETE FROM search_records")
ActiveRecord::Base.connection.execute("DELETE FROM search_records_fts")
else
Search::Record::Trilogy::SHARD_COUNT.times do |shard_id|
ActiveRecord::Base.connection.execute("DELETE FROM search_records_#{shard_id}")
end
end
puts "Reindexing cards..."
Card.find_each do |card|
Current.account = card.account
card.reindex
end
puts "Reindexing comments..."
Comment.find_each do |comment|
Current.account = comment.account
comment.reindex
end