From 9d59d56818fa221a39d0d9f94ca2071afddeacdb Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Thu, 10 Oct 2019 14:17:02 +0200 Subject: [PATCH] Generate all preview for assets at same time --- .../active_storage/representations_controller.rb | 2 +- app/jobs/active_storage/preview_job.rb | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/controllers/active_storage/representations_controller.rb b/app/controllers/active_storage/representations_controller.rb index e1a1a4fa8..928d292f1 100644 --- a/app/controllers/active_storage/representations_controller.rb +++ b/app/controllers/active_storage/representations_controller.rb @@ -30,7 +30,7 @@ module ActiveStorage return true if preview_exists unless processing - ActiveStorage::PreviewJob.perform_later(@blob.id, params[:variation_key]) + ActiveStorage::PreviewJob.perform_later(@blob.id) @blob.attachments.take.record.update(file_processing: true) end diff --git a/app/jobs/active_storage/preview_job.rb b/app/jobs/active_storage/preview_job.rb index 708284766..f1eda5812 100644 --- a/app/jobs/active_storage/preview_job.rb +++ b/app/jobs/active_storage/preview_job.rb @@ -14,12 +14,16 @@ class ActiveStorage::PreviewJob < ActiveStorage::BaseJob retry_on ActiveStorage::IntegrityError, attempts: 3, wait: :exponentially_longer - def perform(blob_id, variation_key) + def perform(blob_id) blob = ActiveStorage::Blob.find(blob_id) - preview = blob.representation(variation_key).processed - blob.attachments.take.record.update(file_processing: false) - + preview = blob.representation(resize_to_limit: Constants::MEDIUM_PIC_FORMAT).processed Rails.logger.info "Preview for the Blod with id: #{blob.id} - successfully generated.\n" \ "Transformations applied: #{preview.variation.transformations}" + + preview = blob.representation(resize_to_limit: Constants::LARGE_PIC_FORMAT).processed + Rails.logger.info "Preview for the Blod with id: #{blob.id} - successfully generated.\n" \ + "Transformations applied: #{preview.variation.transformations}" + + blob.attachments.take.record.update(file_processing: false) end end