A platform for community discussion. Free, open, simple.
FIX: Exclude posts exceeding max length from translation progress (#35723)
Rafael dos Santos Silva09d1e56186d1
diff --git a/plugins/discourse-ai/lib/translation/post_candidates.rb b/plugins/discourse-ai/lib/translation/post_candidates.rbindex 51f32b5d690..b715b62c1d7 100644--- a/plugins/discourse-ai/lib/translation/post_candidates.rb+++ b/plugins/discourse-ai/lib/translation/post_candidates.rb@@ -25,6 +25,7 @@ module DiscourseAi.where(deleted_at: nil).where("posts.user_id > 0").where.not(raw: [nil, ""])+ .where("LENGTH(posts.raw) <= ?", SiteSetting.ai_translation_max_post_length)posts = posts.joins(:topic)if SiteSetting.ai_translation_backfill_limit_to_public_contentdiff --git a/plugins/discourse-ai/spec/lib/translation/post_candidates_spec.rb b/plugins/discourse-ai/spec/lib/translation/post_candidates_spec.rbindex 11207b77984..0bf1ebcc526 100644--- a/plugins/discourse-ai/spec/lib/translation/post_candidates_spec.rb+++ b/plugins/discourse-ai/spec/lib/translation/post_candidates_spec.rb@@ -24,6 +24,16 @@ describe DiscourseAi::Translation::PostCandidates doexpect(DiscourseAi::Translation::PostCandidates.get).not_to include(post)end+ it "does not return posts longer than ai_translation_max_post_length" do+ SiteSetting.ai_translation_max_post_length = 100+ short_post = Fabricate(:post, raw: "This is a short post that fits within the limit.")+ long_post = Fabricate(:post, raw: "a" * 50 + " This is a long post. " + "b" * 50)++ posts = DiscourseAi::Translation::PostCandidates.get+ expect(posts).to include(short_post)+ expect(posts).not_to include(long_post)+ end+describe "SiteSetting.ai_translation_backfill_limit_to_public_content" dofab!(:pm_post) { Fabricate(:post, topic: Fabricate(:private_message_topic)) }fab!(:group_pm_post) do@@ -121,5 +131,16 @@ describe DiscourseAi::Translation::PostCandidates dofr_entry = progress.find { |r| r[:locale] == "fr" }expect(fr_entry).to be_nilend++ it "excludes posts longer than ai_translation_max_post_length from totals" do+ SiteSetting.ai_translation_max_post_length = 100+ short_post = Fabricate(:post, locale: "en_GB", raw: "This is a short post that fits.")+ long_post =+ Fabricate(:post, locale: "fr", raw: "a" * 50 + " This is a long post. " + "b" * 50)++ result = DiscourseAi::Translation::PostCandidates.get_completion_all_locales+ expect(result[:total]).to eq(1)+ expect(result[:posts_with_detected_locale]).to eq(1)+ endendend