@@ -9,23 +9,25 @@ def execute(args)
99 limit = args [ :limit ]
1010 raise Discourse ::InvalidParameters . new ( :limit ) if limit . blank? || limit <= 0
1111
12- return if !SiteSetting . discourse_ai_enabled
13- return if !SiteSetting . ai_translation_enabled
12+ return if !DiscourseAi ::Translation . backfill_enabled?
1413
1514 locales = SiteSetting . content_localization_supported_locales . split ( "|" )
16- return if locales . blank?
17-
1815 locales . each do |locale |
16+ base_locale = locale . split ( "_" ) . first
1917 posts =
2018 Post
2119 . joins (
22- "LEFT JOIN post_localizations pl ON pl.post_id = posts.id AND pl.locale = #{ ActiveRecord ::Base . connection . quote ( locale ) } " ,
20+ "LEFT JOIN post_localizations pl ON pl.post_id = posts.id AND pl.locale LIKE '#{ base_locale } %'" ,
21+ )
22+ . where (
23+ "posts.created_at > ?" ,
24+ SiteSetting . ai_translation_backfill_max_age_days . days . ago ,
2325 )
2426 . where ( deleted_at : nil )
2527 . where ( "posts.user_id > 0" )
2628 . where . not ( raw : [ nil , "" ] )
2729 . where . not ( locale : nil )
28- . where . not ( locale : locale )
30+ . where ( "posts. locale NOT LIKE ' #{ base_locale } %'" )
2931 . where ( "pl.id IS NULL" )
3032
3133 posts = posts . joins ( :topic )
@@ -46,14 +48,6 @@ def execute(args)
4648 )
4749 end
4850
49- if SiteSetting . ai_translation_backfill_max_age_days > 0
50- posts =
51- posts . where (
52- "posts.created_at > ?" ,
53- SiteSetting . ai_translation_backfill_max_age_days . days . ago ,
54- )
55- end
56-
5751 posts = posts . order ( updated_at : :desc ) . limit ( limit )
5852
5953 next if posts . empty?
0 commit comments