A platform for community discussion. Free, open, simple.
FEATURE: extend duration allowed for download
Sam Saffron0cbaa8d813f8
diff --git a/app/models/optimized_image.rb b/app/models/optimized_image.rbindex e5783532c86..654d60a35cc 100644--- a/app/models/optimized_image.rb+++ b/app/models/optimized_image.rb@@ -56,6 +56,15 @@ class OptimizedImage < ActiveRecord::Basereturn thumbnail if thumbnail+ # create the thumbnail otherwise+ original_path = Discourse.store.path_for(upload)++ if original_path.blank?+ # download is protected with a DistributedMutex+ external_copy = Discourse.store.download(upload) rescue nil+ original_path = external_copy.try(:path)+ end+lock(upload.id, width, height) do# may have been generated since we got the lockthumbnail = find_by(upload_id: upload.id, width: width, height: height)@@ -63,13 +72,6 @@ class OptimizedImage < ActiveRecord::Base# return the previous thumbnail if anyreturn thumbnail if thumbnail- # create the thumbnail otherwise- original_path = Discourse.store.path_for(upload)- if original_path.blank?- external_copy = Discourse.store.download(upload) rescue nil- original_path = external_copy.try(:path)- end-if original_path.blank?Rails.logger.error("Could not find file in the store located at url: #{upload.url}")elsediff --git a/lib/file_store/base_store.rb b/lib/file_store/base_store.rbindex 6307465a8fc..df859603918 100644--- a/lib/file_store/base_store.rb+++ b/lib/file_store/base_store.rb@@ -77,7 +77,7 @@ module FileStoreenddef download(upload)- DistributedMutex.synchronize("download_#{upload.sha1}") do+ DistributedMutex.synchronize("download_#{upload.sha1}", validity: 3.minutes) dofilename = "#{upload.sha1}#{File.extname(upload.original_filename)}"file = get_from_cache(filename)