01d16f96d4
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.
29 lines
897 B
Ruby
29 lines
897 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.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
|
|
|
|
puts "Done! Reindexed #{Card.count} cards and #{Comment.count} comments."
|
|
end
|
|
end
|