Skip to content

Commit 6df6266

Browse files
authored
DEV: Backfill translations for recently updated topics and posts first (#231)
1 parent 6e8b183 commit 6df6266

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

app/jobs/scheduled/automatic_translation_backfill.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def fetch_untranslated_model_ids(
4747
AND m.deleted_at IS NULL
4848
AND m.#{content_column} != ''
4949
AND m.user_id > 0
50-
ORDER BY m.id DESC
50+
ORDER BY m.updated_at DESC
5151
LIMIT :limit
5252
SQL
5353
end

spec/jobs/automatic_translation_backfill_spec.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,17 @@ def expect_google_translate(text)
176176
post_7.set_translation("ja", "こんにちは")
177177
end
178178

179-
it "returns correct post ids needing translation in descending id" do
179+
it "returns correct post ids needing translation in descending updated_at" do
180+
# based on the table above, we will return post_7, post_6, post_3, post_2, post_1
181+
# but we will jumble its updated_at to test if it is sorted correctly
182+
post_6.update!(updated_at: 1.day.ago)
183+
post_3.update!(updated_at: 2.days.ago)
184+
post_2.update!(updated_at: 3.days.ago)
185+
post_1.update!(updated_at: 4.days.ago)
186+
post_7.update!(updated_at: 5.days.ago)
187+
180188
result = described_class.new.fetch_untranslated_model_ids(Post, "cooked", 50, %w[de es])
181-
expect(result).to include(post_7.id, post_6.id, post_3.id, post_2.id, post_1.id)
189+
expect(result).to include(post_6.id, post_3.id, post_2.id, post_1.id, post_7.id)
182190
end
183191

184192
it "does not return posts that are deleted" do

0 commit comments

Comments
 (0)