From 834140f0a297d3bee807de513fe287dec5a00fc1 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 29 May 2021 15:44:00 +0100 Subject: [PATCH] Don't dump massive binary PDF data into the job queue Here we were rendering an entire PDF, then passing that PDF into the job queue as an *argument* containing the entire binary of the PDF in a massive string. This means the job object itself would contain that entire PDF. That's bad queueing! We now create the PDF *during* the job (not before it), and pass simple arguments. --- app/controllers/spree/admin/orders_controller.rb | 4 +--- app/mailers/spree/order_mailer.rb | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/spree/admin/orders_controller.rb b/app/controllers/spree/admin/orders_controller.rb index 3eb0116d46..b1ee4f3dc6 100644 --- a/app/controllers/spree/admin/orders_controller.rb +++ b/app/controllers/spree/admin/orders_controller.rb @@ -81,9 +81,7 @@ module Spree end def invoice - pdf = InvoiceRenderer.new.render_to_string(@order) - - Spree::OrderMailer.invoice_email(@order.id, pdf).deliver_later + Spree::OrderMailer.invoice_email(@order.id).deliver_later flash[:success] = t('admin.orders.invoice_email_sent') respond_with(@order) { |format| diff --git a/app/mailers/spree/order_mailer.rb b/app/mailers/spree/order_mailer.rb index a8056c1778..889a419b5e 100644 --- a/app/mailers/spree/order_mailer.rb +++ b/app/mailers/spree/order_mailer.rb @@ -49,8 +49,10 @@ module Spree end end - def invoice_email(order_or_order_id, pdf) + def invoice_email(order_or_order_id) @order = find_order(order_or_order_id) + pdf = InvoiceRenderer.new.render_to_string(@order) + attach_file("invoice-#{@order.number}.pdf", pdf) I18n.with_locale valid_locale(@order.user) do mail(to: @order.email,