Avoid ActionController when render mail, AT loaded

This avoids unnecessarily loading `ActionController::Base` when
rendering mail after Action Text has been loaded.

Before:

```
$ bin/rails r 'Benchmark.memory { |x| x.report("load"){ MyBlankMailer.blank_email.body } }'
Calculating -------------------------------------
                load    12.679M memsize (     1.927M retained)
                       101.143k objects (    19.947k retained)
                        50.000  strings (    50.000  retained)
```

After:

```
$ bin/rails r 'Benchmark.memory { |x| x.report("load"){ MyBlankMailer.blank_email.body } }'
Calculating -------------------------------------
                load     7.678M memsize (     1.302M retained)
                        61.420k objects (    13.644k retained)
                        50.000  strings (    50.000  retained)
```
This commit is contained in:
Jonathan Hefner 2022-05-16 14:39:09 -05:00
parent 7415b93580
commit c2a3ff0027
1 changed files with 8 additions and 6 deletions

View File

@ -51,20 +51,22 @@ module ActionText
end
initializer "action_text.helper" do
%i[action_controller_base action_mailer].each do |abstract_controller|
ActiveSupport.on_load(abstract_controller) do
%i[action_controller_base action_mailer].each do |base|
ActiveSupport.on_load(base) do
helper ActionText::Engine.helpers
end
end
end
initializer "action_text.renderer" do
ActiveSupport.on_load(:action_text_content) do
self.default_renderer = Class.new(ActionController::Base).renderer
ActiveSupport.on_load(:action_controller_base) do
ActiveSupport.on_load(:action_text_content) do
self.default_renderer = Class.new(ActionController::Base).renderer
end
end
%i[action_controller_base action_mailer].each do |abstract_controller|
ActiveSupport.on_load(abstract_controller) do
%i[action_controller_base action_mailer].each do |base|
ActiveSupport.on_load(base) do
around_action do |controller, action|
ActionText::Content.with_renderer(controller, &action)
end