mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-28 01:56:01 -05:00
add DistributedMutex around uploads/optimized_images creation
This commit is contained in:
parent
440331e36e
commit
6ae9bcab56
2 changed files with 96 additions and 92 deletions
|
@ -6,6 +6,7 @@ class OptimizedImage < ActiveRecord::Base
|
|||
def self.create_for(upload, width, height, opts={})
|
||||
return unless width > 0 && height > 0
|
||||
|
||||
DistributedMutex.synchronize("optimized_image_#{upload.id}_#{width}_#{height}") do
|
||||
# do we already have that thumbnail?
|
||||
thumbnail = find_by(upload_id: upload.id, width: width, height: height)
|
||||
|
||||
|
@ -73,6 +74,7 @@ class OptimizedImage < ActiveRecord::Base
|
|||
|
||||
thumbnail
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
OptimizedImage.transaction do
|
||||
|
|
|
@ -52,6 +52,7 @@ class Upload < ActiveRecord::Base
|
|||
def self.create_for(user_id, file, filename, filesize, options = {})
|
||||
sha1 = Digest::SHA1.file(file).hexdigest
|
||||
|
||||
DistributedMutex.synchronize("upload_#{sha1}") do
|
||||
# do we already have that upload?
|
||||
upload = find_by(sha1: sha1)
|
||||
|
||||
|
@ -90,6 +91,7 @@ class Upload < ActiveRecord::Base
|
|||
# return the uploaded file
|
||||
upload
|
||||
end
|
||||
end
|
||||
|
||||
def self.resize_image(filename, file, upload)
|
||||
begin
|
||||
|
|
Loading…
Reference in a new issue