Optimization:Only Enqueue UpdateMainImageBackgroundHexWorker If Main Image Changes (#10325)
This commit is contained in:
parent
f0b124cc26
commit
f2b59cc882
2 changed files with 10 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue