From 8bd9be5533139c87f4d344756de84c8f76290d72 Mon Sep 17 00:00:00 2001 From: Nat Date: Mon, 30 Jun 2025 18:23:53 +0800 Subject: [PATCH 1/2] DEV: Add index --- ...630040849_add_index_post_locale_post_id.rb | 21 +++++++++++++++++++ plugin.rb | 4 ++++ 2 files changed, 25 insertions(+) create mode 100644 db/migrate/20250630040849_add_index_post_locale_post_id.rb diff --git a/db/migrate/20250630040849_add_index_post_locale_post_id.rb b/db/migrate/20250630040849_add_index_post_locale_post_id.rb new file mode 100644 index 00000000..becff146 --- /dev/null +++ b/db/migrate/20250630040849_add_index_post_locale_post_id.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class AddIndexPostLocalePostId < ActiveRecord::Migration[7.2] + disable_ddl_transaction! + + def up + # clean up invalid index if index creation timeout + execute <<~SQL + DROP INDEX IF EXISTS index_discourse_translator_post_locales_on_post_id + SQL + + execute <<~SQL + CREATE UNIQUE INDEX CONCURRENTLY index_discourse_translator_post_locales_on_post_id + ON discourse_translator_post_locales (post_id) + SQL + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/plugin.rb b/plugin.rb index 2258e359..f5976b04 100644 --- a/plugin.rb +++ b/plugin.rb @@ -31,6 +31,10 @@ module ::DiscourseTranslator Topic.prepend(DiscourseTranslator::Extensions::TopicExtension) end + TopicView.on_preload do |topic_view| + topic_view.instance_variable_set(:@posts, topic_view.posts.includes(:content_locale)) + end + add_to_serializer :post, :can_translate do scope.can_translate?(object) end From 55d35209876c88be9a77d997588ec92f3057146f Mon Sep 17 00:00:00 2001 From: Nat Date: Mon, 30 Jun 2025 18:39:46 +0800 Subject: [PATCH 2/2] nono --- app/models/discourse_translator/post_locale.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/discourse_translator/post_locale.rb b/app/models/discourse_translator/post_locale.rb index 305c7b62..afbaa2ac 100644 --- a/app/models/discourse_translator/post_locale.rb +++ b/app/models/discourse_translator/post_locale.rb @@ -21,3 +21,7 @@ class PostLocale < ActiveRecord::Base # created_at :datetime not null # updated_at :datetime not null # +# Indexes +# +# index_discourse_translator_post_locales_on_post_id (post_id) UNIQUE +#