b571303385
It doesn't actually work, and even if we could make it work reliably we are better off if the records always know to go to the right shard. It does make the interface a bit more complicated as we need to select the right shard class with `for(account_id)`.
23 lines
828 B
Ruby
23 lines
828 B
Ruby
namespace :search do
|
|
desc "Reindex all cards and comments in the search index"
|
|
task reindex: :environment do
|
|
puts "Clearing search records..."
|
|
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.includes(:rich_text_description).find_each(&:reindex)
|
|
|
|
puts "Reindexing comments..."
|
|
Comment.includes(:rich_text_body, :card).find_each(&:reindex)
|
|
|
|
puts "Done! Reindexed #{Card.count} cards and #{Comment.count} comments."
|
|
end
|
|
end
|