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
2 changes: 1 addition & 1 deletion app/jobs/scheduled/automatic_translation_backfill.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def fetch_untranslated_model_ids(
AND m.deleted_at IS NULL
AND m.#{content_column} != ''
AND m.user_id > 0
ORDER BY m.id DESC
ORDER BY m.updated_at DESC
LIMIT :limit
SQL
end
Expand Down
12 changes: 10 additions & 2 deletions spec/jobs/automatic_translation_backfill_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,17 @@ def expect_google_translate(text)
post_7.set_translation("ja", "こんにちは")
end

it "returns correct post ids needing translation in descending id" do
it "returns correct post ids needing translation in descending updated_at" do
# based on the table above, we will return post_7, post_6, post_3, post_2, post_1
# but we will jumble its updated_at to test if it is sorted correctly
post_6.update!(updated_at: 1.day.ago)
post_3.update!(updated_at: 2.days.ago)
post_2.update!(updated_at: 3.days.ago)
post_1.update!(updated_at: 4.days.ago)
post_7.update!(updated_at: 5.days.ago)

result = described_class.new.fetch_untranslated_model_ids(Post, "cooked", 50, %w[de es])
expect(result).to include(post_7.id, post_6.id, post_3.id, post_2.id, post_1.id)
expect(result).to include(post_6.id, post_3.id, post_2.id, post_1.id, post_7.id)
end

it "does not return posts that are deleted" do
Expand Down
Loading