From 023af6527febdfb5f1472c000087924c8a430a02 Mon Sep 17 00:00:00 2001 From: Donovan Daniels Date: Mon, 28 Oct 2024 20:21:51 -0500 Subject: [PATCH] Only perform iqdb update if md5 changed --- app/jobs/update_external_cache_job.rb | 1 + app/models/external_api_image.rb | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) 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?)