mirror of
https://github.com/discourse/discourse.git
synced 2025-03-03 23:08:39 +08:00
PERF: Migrate search data after locale rename (#11831)
The default locale `en_US` has been renamed into `en`. This tries to migrate existing search data to avoid resource intensive reindexing.
This commit is contained in:
parent
77c48644eb
commit
e65c5b0aad
@ -0,0 +1,28 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class MigrateSearchDataAfterDefaultLocaleRename < ActiveRecord::Migration[6.0]
|
||||||
|
def up
|
||||||
|
move_search_data("category_search_data")
|
||||||
|
move_search_data("post_search_data")
|
||||||
|
move_search_data("tag_search_data")
|
||||||
|
move_search_data("topic_search_data")
|
||||||
|
move_search_data("user_search_data")
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
raise ActiveRecord::IrreversibleMigration
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def move_search_data(table_name)
|
||||||
|
execute <<~SQL
|
||||||
|
UPDATE #{table_name} x
|
||||||
|
SET locale = 'en'
|
||||||
|
WHERE locale = 'en_US'
|
||||||
|
SQL
|
||||||
|
rescue
|
||||||
|
# Probably a unique key constraint violation. A background job might have inserted conflicting data during the UPDATE.
|
||||||
|
# We can safely ignore this error. The ReindexSearch job will eventually fix the data.
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user