REFACTOR: Reuse `Discourse.store` instance
Calling `Discourse.store` creates a new instance of a store each time.
This commit is contained in:
parent
a8330222f9
commit
bcb8b3fab9
|
@ -50,12 +50,14 @@ class OptimizedImage < ActiveRecord::Base
|
||||||
|
|
||||||
return thumbnail if thumbnail
|
return thumbnail if thumbnail
|
||||||
|
|
||||||
|
store = Discourse.store
|
||||||
|
|
||||||
# create the thumbnail otherwise
|
# create the thumbnail otherwise
|
||||||
original_path = Discourse.store.path_for(upload)
|
original_path = store.path_for(upload)
|
||||||
|
|
||||||
if original_path.blank?
|
if original_path.blank?
|
||||||
# download is protected with a DistributedMutex
|
# download is protected with a DistributedMutex
|
||||||
external_copy = Discourse.store.download_safe(upload)
|
external_copy = store.download_safe(upload)
|
||||||
original_path = external_copy&.path
|
original_path = external_copy&.path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -106,8 +108,7 @@ class OptimizedImage < ActiveRecord::Base
|
||||||
|
|
||||||
# store the optimized image and update its url
|
# store the optimized image and update its url
|
||||||
File.open(temp_path) do |file|
|
File.open(temp_path) do |file|
|
||||||
url =
|
url = store.store_optimized_image(file, thumbnail, nil, secure: upload.secure?)
|
||||||
Discourse.store.store_optimized_image(file, thumbnail, nil, secure: upload.secure?)
|
|
||||||
if url.present?
|
if url.present?
|
||||||
thumbnail.url = url
|
thumbnail.url = url
|
||||||
thumbnail.save
|
thumbnail.save
|
||||||
|
@ -124,7 +125,7 @@ class OptimizedImage < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
# make sure we remove the cached copy from external stores
|
# make sure we remove the cached copy from external stores
|
||||||
external_copy&.close if Discourse.store.external?
|
external_copy&.close if store.external?
|
||||||
|
|
||||||
thumbnail
|
thumbnail
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue