Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/models/discourse_translator/post_locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
21 changes: 21 additions & 0 deletions db/migrate/20250630040849_add_index_post_locale_post_id.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading