A platform for community discussion. Free, open, simple.
PERF: reuse renderer when rendering email templates
Sam Saffron71ea4ad7fca4
diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rbindex ee5a516a734..de8ac561eb9 100644--- a/app/mailers/user_notifications.rb+++ b/app/mailers/user_notifications.rb@@ -589,7 +589,7 @@ class UserNotifications < ActionMailer::Baseendunless translation_override_exists- html = UserNotificationRenderer.with_view_paths(Rails.configuration.paths["app/views"]).render(+ html = UserNotificationRenderer.instance.render(template: 'email/notification',format: :html,locals: { context_posts: context_posts,diff --git a/app/services/user_notification_renderer.rb b/app/services/user_notification_renderer.rbindex 8ad7d209145..edf11712838 100644--- a/app/services/user_notification_renderer.rb+++ b/app/services/user_notification_renderer.rb@@ -4,4 +4,10 @@ class UserNotificationRenderer < ActionView::Baseinclude ApplicationHelperinclude UserNotificationsHelperinclude EmailHelper++ def self.instance+ @instance ||= UserNotificationRenderer.with_view_paths(+ Rails.configuration.paths["app/views"]+ )+ endenddiff --git a/lib/email/message_builder.rb b/lib/email/message_builder.rbindex d1e83b03e01..654c4ae3c67 100644--- a/lib/email/message_builder.rb+++ b/lib/email/message_builder.rb@@ -94,9 +94,7 @@ module Emailhtml_override.gsub!("%{respond_instructions}", "")end- html = UserNotificationRenderer.with_view_paths(- Rails.configuration.paths["app/views"]- ).render(+ html = UserNotificationRenderer.instance.render(template: 'layouts/email_template',format: :html,locals: { html_body: html_override.html_safe }diff --git a/lib/email/renderer.rb b/lib/email/renderer.rbindex 641fb207bed..2f9203bd6c3 100644--- a/lib/email/renderer.rb+++ b/lib/email/renderer.rb@@ -18,9 +18,7 @@ module Emailstyle = if @message.html_partEmail::Styles.new(@message.html_part.body.to_s, @opts)else- unstyled = UserNotificationRenderer.with_view_paths(- Rails.configuration.paths["app/views"]- ).render(+ unstyled = UserNotificationRenderer.instance.render(template: 'layouts/email_template',format: :html,locals: { html_body: PrettyText.cook(text).html_safe }