Optimization:Only Enqueue UpdateMainImageBackgroundHexWorker If Main Image Changes (#10325)

This commit is contained in:
Molly Struve 2020-09-14 11:37:38 -05:00 committed by GitHub
parent f0b124cc26
commit f2b59cc882
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View file

@ -422,6 +422,7 @@ class Article < ApplicationRecord
end
def update_main_image_background_hex
return unless saved_changes.key?("main_image")
return if main_image.blank? || main_image_background_hex_color != "#dddddd"
Articles::UpdateMainImageBackgroundHexWorker.perform_async(id)

View file

@ -765,6 +765,15 @@ RSpec.describe Article, type: :model do
end
expect(article).to have_received(:update_main_image_background_hex)
end
it "does not enqueue a job if main_image has not changed" do
article.save
allow(article).to receive(:update_main_image_background_hex).and_call_original
sidekiq_assert_no_enqueued_jobs(only: Articles::UpdateMainImageBackgroundHexWorker) do
article.save
end
expect(article).to have_received(:update_main_image_background_hex)
end
end
describe "async score calc" do