Skip to content

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.rb
index e5783532c86..654d60a35cc 100644
--- a/app/models/optimized_image.rb
+++ b/app/models/optimized_image.rb
@@ -56,6 +56,15 @@ class OptimizedImage < ActiveRecord::Base
return 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 lock
thumbnail = find_by(upload_id: upload.id, width: width, height: height)
@@ -63,13 +72,6 @@ class OptimizedImage < ActiveRecord::Base
# return the previous thumbnail if any
return 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}")
else
diff --git a/lib/file_store/base_store.rb b/lib/file_store/base_store.rb
index 6307465a8fc..df859603918 100644
--- a/lib/file_store/base_store.rb
+++ b/lib/file_store/base_store.rb
@@ -77,7 +77,7 @@ module FileStore
end
def download(upload)
- DistributedMutex.synchronize("download_#{upload.sha1}") do
+ DistributedMutex.synchronize("download_#{upload.sha1}", validity: 3.minutes) do
filename = "#{upload.sha1}#{File.extname(upload.original_filename)}"
file = get_from_cache(filename)