Don't perform API request for .exist? of synced files

This commit is contained in:
Max Melentiev
2019-02-05 18:03:11 +05:30
parent 4fe07942d2
commit 2ea6e772df
2 changed files with 8 additions and 4 deletions

View File

@@ -101,9 +101,11 @@ module Paperclip
raise '#path is not available for this type of storage, use #to_file instead'
end
# By default checks main store if synced and cache otherwise.
# Checks if attached file exists. When store_id is not given
# it uses fast check and does not perform API request for synced files
def exists?(style = default_style, store_id = nil)
store_id ||= synced_to?(self.class.main_store_id) ? self.class.main_store_id : :cache
return true if !store_id && synced_to?(self.class.main_store_id)
store_id ||= :cache
!self.class.directory_for(store_id).files.head(key(style)).nil?
end

View File

@@ -113,9 +113,11 @@ module Paperclip
create_tempfile(response.body) if response.is_a?(Net::HTTPOK)
end
# By default checks main store if synced and cache otherwise.
# Checks if attached file exists. When store_id is not given
# it uses fast check and does not perform API request for synced files
def exists?(style = default_style, store_id = nil)
store_id ||= instance_read(:synced_to_s3) ? :s3 : :cache
return true if !store_id && instance_read(:synced_to_s3)
store_id ||= :cache
case store_id
when :cache
File.exist?(filesystem_path(style))