Mange / roadie-rails

Making HTML emails comfortable for the Rails rockstars
MIT License
367 stars 66 forks source link

inline erb .. or .. cache inlined output #67

Closed twetzel closed 8 years ago

twetzel commented 8 years ago

Hi,

I have a problem I use sidekiq to generate a lot of mails, which uses an immense load of memory!

Would it be possible to just inline css via maybe a rake task or command directly after deploy, so I don't need to on each mail send?

the output should be erb again, so the content could still change.

.. thanks a lot .. Torsten

Mange commented 8 years ago

That would be very hard as we need a parser that can avoid looking at the erb blocks and output then unchanged. In addition, it would make it impossible to use helpers to generate tags, we would have to follow inside partials and separate them into different partials as two mails with different styles could use the same partial, and a bunch of other problems.

This is out of scope for this project.

Den tis 18 okt. 2016 00:57Torsten Wetzel notifications@github.com skrev:

Hi,

I have a problem I use sidekiq to generate a lot of mails, which uses an immense load of memory!

Would it be possible to just inline css via maybe a rake task or command directly after deploy, so I don't need to on each mail send?

the output should be erb again, so the content could still change.

.. thanks a lot .. Torsten

β€” You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Mange/roadie-rails/issues/67, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAGP4DcRey69wvJW0T1DjCpjEJ3350-ks5q0_1HgaJpZM4KZMyE .

twetzel commented 8 years ago

would be totally OK to just inline one view .. so i.e.: Roadie.inlineErb("/path/to/erb", {styles: "path/to/styles"}) .. than I could make a rake or helper task which inlines all views, partials and layouts .. so each single mail would be generated in no time

My Sidekiq-Job generates maybe about 100 mails per Job and is already way over 500 MB each time .. after some researching I realized roadie is the bottleneck there

Mange commented 8 years ago

You could build this manually using plain Roadie if you go with a template engine that is parseable by an HTML parser, for example mustache.

I'd like to optimize memory usage if possible. Have you tried using simpler stylesheets? It'd be great to get some optimizations going if you have a good test case. ☺️

Den tis 18 okt. 2016 12:42Torsten Wetzel notifications@github.com skrev:

would be totally OK to just inline one view .. so i.e.: Roadie.inlineErb("/path/to/erb", {styles: "path/to/styles"}) .. than I could make a rake or helper task which inlines all views, partials and layouts .. so each single mail would be generated in no time

My Sidekiq-Job generates maybe about 100 mails per Job and is already way over 500 MB each time .. after some researching I realized roadie is the bottleneck there

β€” You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub https://github.com/Mange/roadie-rails/issues/67#issuecomment-254471301, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAGP1_cB3MU68WhGZlbczeLx-JSokCRks5q1KKDgaJpZM4KZMyE .

twetzel commented 7 years ago

Hey @Mange, sorry have to bother you again.

First of all thanks for the last reply, I took your suggestions:

.. but the Problem appears again, now its way more than 1 GB mem used. (The app is growing, so their may be a good 500+ mails per action)

I totally understand this is out of scope for roadie-rails .. so would give it a try myself.

Would you have some tips to start with .. I would like to have following features:

And than wrap it together in a new gem like, roadie-piped or something

.. thanks a lot .. cheers Torsten

Mange commented 7 years ago

You are more than welcome to try to implement that. I have no idea on how to parse the template enough to even inline styles for almost static HTML. Then you have things like class names toggled depending on some erb expression. What should one inline then?

I think you can get pretty close by using normal Roadie gem. You could have a rake task that inline styles on simple templates like Mustache and output them to app/views. Then you can run that on deployments or before committing. You just need to make sure that no matter what you add the file must be valid XML (eg. for conditionals, don't have a shared static closing tag with the opening tag depending on the condition) and don't apply any classes or structure depending on the variables.

If you have simple templates where you just enumerate values and output the same block of HTML for each, just having text and URL differently, it could work for you.

I might rewrite all of this in Rust at one point, just to have a larger project in my new language. That should make memory usage much lower. Don't count on it, though, as I haven't used roadie myself for more than three years.

Good luck! I mean it. I'd love to hear about something like this working. 😊

Den fre 5 maj 2017 13:59Torsten Wetzel notifications@github.com skrev:

Hey @Mange https://github.com/Mange, sorry have to bother you again.

First of all thanks for the last reply, I took your suggestions:

  • simple css (7.5 kb)
  • higher memory for sidekiq (for huge operations even a single-worker-queue)

.. but the Problem appears again, now its way more than 1 GB mem used. (The app is growing, so their may be a good 500+ mails per action)

I totally understand this is out of scope for roadie-rails .. so would give it a try myself.

Would you have some tips to start with .. I would like to have following features:

  • inline all styles in _mailer folder on action x (deployment / bundle assets)*
  • a config-file (which file uses which style .. additional helpers, templates)
  • keep erb tags untouched (maybe just allow a few tag-helpers .. ie: link_to, mail_to, image_tag .. and add a style: .. attribute )

And than wrap it together in a new gem like, roadie-piped or something

.. thanks a lot ..

cheers Torsten

β€” You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/Mange/roadie-rails/issues/67#issuecomment-299446440, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAGPw5xnf1uu00qQCzf6ictZtuCQPUKks5r2w8LgaJpZM4KZMyE .