diff --git a/app/jobs/update_external_cache_job.rb b/app/jobs/update_external_cache_job.rb index c53a06a..a4c98cc 100644 --- a/app/jobs/update_external_cache_job.rb +++ b/app/jobs/update_external_cache_job.rb @@ -4,6 +4,7 @@ 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 c09aec0..c0d326c 100644 --- a/app/models/external_api_image.rb +++ b/app/models/external_api_image.rb @@ -85,6 +85,15 @@ class ExternalAPIImage < ApplicationRecord end end + def image_changed? + case site + when "e621", "femboyfans" + cached_data.try(:dig, "file", "md5") != cached_data_before_last_save.try(:dig, "file", "md5") + else + data_error("format image_changed?") + end + end + def is_deleted? case site when "e621", "femboyfans" @@ -151,7 +160,7 @@ class ExternalAPIImage < ApplicationRecord update(cached_data: data, cache_last_updated_at: Time.now) if is_deleted? api_image.remove_iqdb - else + elsif image_changed? api_image.update_iqdb end api_image.update(is_viewable: !is_deleted?)