lib/alchemy/dragonfly/s3/create_picture_thumb.rb in alchemy-dragonfly-s3-5.2.0 vs lib/alchemy/dragonfly/s3/create_picture_thumb.rb in alchemy-dragonfly-s3-5.2.1

- old
+ new

@@ -3,25 +3,26 @@ module Alchemy module Dragonfly module S3 class CreatePictureThumb def self.call(variant, signature, uid) + return if !variant.picture.valid? + # create the thumb before uploading # to prevent db race conditions - thumb = variant.picture.thumbs.create!( - picture: variant.picture, - signature: signature, - uid: uid, - ) + @thumb = Alchemy::PictureThumb.create_or_find_by!(signature: signature) do |thumb| + thumb.picture = variant.picture + thumb.uid = uid + end begin # fetch and process the image image = variant.image # upload the processed image image.store(path: uid) rescue RuntimeError, Excon::Error => e - Rails.logger.warn(e) + ErrorTracking.notification_handler.call(e) # destroy the thumb if processing or upload fails - thumb.destroy + @thumb&.destroy end end end end end