Change local media attachments to perform heavy processing asynchronously (#13210)
Fix #9106
This commit is contained in:
parent
764b89939f
commit
9660aa4543
15 changed files with 165 additions and 17 deletions
30
lib/paperclip/attachment_extensions.rb
Normal file
30
lib/paperclip/attachment_extensions.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Paperclip
|
||||
module AttachmentExtensions
|
||||
# We overwrite this method to support delayed processing in
|
||||
# Sidekiq. Since we process the original file to reduce disk
|
||||
# usage, and we still want to generate thumbnails straight
|
||||
# away, it's the only style we need to exclude
|
||||
def process_style?(style_name, style_args)
|
||||
if style_name == :original && instance.respond_to?(:delay_processing?) && instance.delay_processing?
|
||||
false
|
||||
else
|
||||
style_args.empty? || style_args.include?(style_name)
|
||||
end
|
||||
end
|
||||
|
||||
def reprocess_original!
|
||||
old_original_path = path(:original)
|
||||
reprocess!(:original)
|
||||
new_original_path = path(:original)
|
||||
|
||||
if new_original_path != old_original_path
|
||||
@queued_for_delete << old_original_path
|
||||
flush_deletes
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Paperclip::Attachment.prepend(Paperclip::AttachmentExtensions)
|
Loading…
Add table
Add a link
Reference in a new issue