mirror of
https://ghfast.top/https://github.com/discourse/discourse-translator.git
synced 2026-07-17 11:56:50 +08:00
Currently, `Topic` and `Post` have detected_language and translations in custom fields, e.g.
```
post.custom_fields[DiscourseTranslator::DETECTED_LANG_CUSTOM_FIELD]
post.custom_fields[DiscourseTranslator::TRANSLATED_CUSTOM_FIELD]
topic.custom_fields[DiscourseTranslator::DETECTED_LANG_CUSTOM_FIELD]
topic.custom_fields[DiscourseTranslator::TRANSLATED_CUSTOM_FIELD]
```
We are moving this into 4 tables/models
```
post has_one :content_locale, class_name: "DiscourseTranslator::PostLocale"
post has_many :translations, class_name: "DiscourseTranslator::PostTranslation"
topic has_one :content_locale, class_name: "DiscourseTranslator::TopicLocale"
topic has_many :translations, class_name: "DiscourseTranslator::TopicTranslation"
```
Since there are a lot of duplicates, this is implemented on the `Post` and `Topic` using a `Concern`, and any future translatable content can inherit this concern.
This PR also gets rid of the previous N+1 which happens when determining if the 🌐 translate button should appear for each post.
17 lines
459 B
Ruby
17 lines
459 B
Ruby
# frozen_string_literal: true
|
|
|
|
class CreateTranslationIndexes < ActiveRecord::Migration[7.2]
|
|
disable_ddl_transaction!
|
|
|
|
def change
|
|
add_index :discourse_translator_topic_translations,
|
|
%i[topic_id locale],
|
|
unique: true,
|
|
algorithm: :concurrently
|
|
|
|
add_index :discourse_translator_post_translations,
|
|
%i[post_id locale],
|
|
unique: true,
|
|
algorithm: :concurrently
|
|
end
|
|
end
|