A platform for community discussion. Free, open, simple.
DEV: Use common candidate helper for backfill job (#34364)
Natalie Tay56f2310fb468
diff --git a/plugins/discourse-ai/app/jobs/scheduled/posts_locale_detection_backfill.rb b/plugins/discourse-ai/app/jobs/scheduled/posts_locale_detection_backfill.rbindex 0a96cd3e887..316fa9e8708 100644--- a/plugins/discourse-ai/app/jobs/scheduled/posts_locale_detection_backfill.rb+++ b/plugins/discourse-ai/app/jobs/scheduled/posts_locale_detection_backfill.rb@@ -12,28 +12,12 @@ module Jobslimit = SiteSetting.ai_translation_backfill_hourly_rate / (60 / 5) # this job runs in 5-minute intervalsposts =- Post+ DiscourseAi::Translation::PostCandidates+ .get().where(locale: nil)- .where(deleted_at: nil)- .where("posts.user_id > 0")- .where("posts.created_at > ?", SiteSetting.ai_translation_backfill_max_age_days.days.ago)- .where.not(raw: [nil, ""])+ .order(updated_at: :desc)+ .limit(limit)- if SiteSetting.ai_translation_backfill_limit_to_public_content- posts =- posts- .joins(:topic)- .where(topics: { category_id: Category.where(read_restricted: false).select(:id) })- .where("archetype != ?", Archetype.private_message)- else- posts =- posts.joins(:topic).where(- "topics.archetype != ? OR EXISTS (SELECT 1 FROM topic_allowed_groups WHERE topic_id = topics.id)",- Archetype.private_message,- )- end-- posts = posts.order(updated_at: :desc).limit(limit)return if posts.empty?posts.each do |post|diff --git a/plugins/discourse-ai/app/jobs/scheduled/topics_locale_detection_backfill.rb b/plugins/discourse-ai/app/jobs/scheduled/topics_locale_detection_backfill.rbindex c917ddb6d59..37af4b2f916 100644--- a/plugins/discourse-ai/app/jobs/scheduled/topics_locale_detection_backfill.rb+++ b/plugins/discourse-ai/app/jobs/scheduled/topics_locale_detection_backfill.rb@@ -12,26 +12,12 @@ module Jobslimit = SiteSetting.ai_translation_backfill_hourly_rate / (60 / 5) # this job runs in 5-minute intervalstopics =- Topic- .where(locale: nil, deleted_at: nil)- .where("topics.user_id > 0")- .where("topics.created_at > ?", SiteSetting.ai_translation_backfill_max_age_days.days.ago)+ DiscourseAi::Translation::TopicCandidates+ .get()+ .where(locale: nil)+ .order(updated_at: :desc)+ .limit(limit)- if SiteSetting.ai_translation_backfill_limit_to_public_content- topics =- topics.where(category_id: Category.where(read_restricted: false).select(:id)).where(- "archetype != ?",- Archetype.private_message,- )- else- topics =- topics.where(- "archetype != ? OR EXISTS (SELECT 1 FROM topic_allowed_groups WHERE topic_id = topics.id)",- Archetype.private_message,- )- end-- topics = topics.order(updated_at: :desc).limit(limit)return if topics.empty?topics.each do |topic|