PERF: Move dominant color calculation to separate job (#18501)

This will ensure that any potential problems with this process do not affect the performance or reliability of the PeriodicalUpdates job.
This commit is contained in:
David Taylor 2022-10-06 13:26:08 +01:00 committed by GitHub
parent 3629b2de1b
commit 3115f38de2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 2 deletions

View File

@ -0,0 +1,11 @@
# frozen_string_literal: true
module Jobs
class BackfillDominantColors < ::Jobs::Scheduled
every 15.minutes
def execute(args)
Upload.backfill_dominant_colors!(25)
end
end
end

View File

@ -48,8 +48,6 @@ module Jobs
Category.auto_bump_topic! Category.auto_bump_topic!
Upload.backfill_dominant_colors!(25)
nil nil
end end

View File

@ -666,6 +666,19 @@ RSpec.describe Upload do
expect(red_image.dominant_color).to eq("FF0000") expect(red_image.dominant_color).to eq("FF0000")
end end
it "is backfilled by the job" do
expect(white_image.dominant_color).to eq(nil)
expect(red_image.dominant_color).to eq(nil)
Jobs::BackfillDominantColors.new.execute({})
white_image.reload
red_image.reload
expect(white_image.dominant_color).to eq("FFFFFF")
expect(red_image.dominant_color).to eq("FF0000")
end
it "stores an empty string for non-image uploads" do it "stores an empty string for non-image uploads" do
expect(not_an_image.dominant_color).to eq(nil) expect(not_an_image.dominant_color).to eq(nil)
expect(not_an_image.dominant_color(calculate_if_missing: true)).to eq("") expect(not_an_image.dominant_color(calculate_if_missing: true)).to eq("")