From 41177bc37a86d2cc4c66702c9459f9b395bd9da4 Mon Sep 17 00:00:00 2001 From: Donovan Daniels Date: Mon, 28 Oct 2024 20:34:43 -0500 Subject: [PATCH] prevent a single image queuing 10+ jobs --- app/jobs/update_external_cache_job.rb | 1 - app/models/external_api_image.rb | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/jobs/update_external_cache_job.rb b/app/jobs/update_external_cache_job.rb index a4c98cc..c53a06a 100644 --- a/app/jobs/update_external_cache_job.rb +++ b/app/jobs/update_external_cache_job.rb @@ -4,7 +4,6 @@ class UpdateExternalCacheJob < ApplicationJob queue_as :cache def perform(image) - return unless image.cache_expired? || image.cached_data.blank? image.update_cache! end end diff --git a/app/models/external_api_image.rb b/app/models/external_api_image.rb index c0d326c..fdd544c 100644 --- a/app/models/external_api_image.rb +++ b/app/models/external_api_image.rb @@ -145,7 +145,9 @@ class ExternalAPIImage < ApplicationRecord end def update_cache + return if @cache_updated UpdateExternalCacheJob.perform_later(self) + @cache_updated = true end def update_cache!