Only perform iqdb update if md5 changed
This commit is contained in:
parent
c2a315b945
commit
023af6527f
@ -4,6 +4,7 @@ class UpdateExternalCacheJob < ApplicationJob
|
|||||||
queue_as :cache
|
queue_as :cache
|
||||||
|
|
||||||
def perform(image)
|
def perform(image)
|
||||||
|
return unless image.cache_expired? || image.cached_data.blank?
|
||||||
image.update_cache!
|
image.update_cache!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -85,6 +85,15 @@ class ExternalAPIImage < ApplicationRecord
|
|||||||
end
|
end
|
||||||
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?
|
def is_deleted?
|
||||||
case site
|
case site
|
||||||
when "e621", "femboyfans"
|
when "e621", "femboyfans"
|
||||||
@ -151,7 +160,7 @@ class ExternalAPIImage < ApplicationRecord
|
|||||||
update(cached_data: data, cache_last_updated_at: Time.now)
|
update(cached_data: data, cache_last_updated_at: Time.now)
|
||||||
if is_deleted?
|
if is_deleted?
|
||||||
api_image.remove_iqdb
|
api_image.remove_iqdb
|
||||||
else
|
elsif image_changed?
|
||||||
api_image.update_iqdb
|
api_image.update_iqdb
|
||||||
end
|
end
|
||||||
api_image.update(is_viewable: !is_deleted?)
|
api_image.update(is_viewable: !is_deleted?)
|
||||||
|
Loading…
Reference in New Issue
Block a user