livebg / smailer

Simple newsletter mailer for Rails
29 stars 14 forks source link

Configurability of mail keys #9

Open j-a-m-l opened 9 years ago

j-a-m-l commented 9 years ago

Currently the Smailer::Modesl::MailKey.generate method is using MD5 with a fixed string and the email as salt.

I think that at least the string should be configurable. What about reading that string from the configuration?

I also think that it could admit a block, so it's much more customizable.

What do you think? I would be pleased to implement it.

mitio commented 9 years ago

You're absolutely right, the salt needs to be externally configurable.

There are some other architectural changes which I've had in mind from using this system in production with tens of thousands of emails daily. I'm open to discuss these observations I have if you're open to implementing some of them.

j-a-m-l commented 9 years ago

Ok, so what are your ideas? I think that your experience would be very valuable, so I could develop some of them, specially the ones that are useful to my engine.

mitio commented 9 years ago

Here are some thoughts (sorry it turned a bit long):

Slow queueing

When you have a few tens of thousands of emails to send daily, enqueueing them for sending means taking these records from the list of subscribers and inserting corresponding rows in queued_mails, going through the ActiveRecord class QueuedMail, creating objects, executing callbacks, etc. As one can imagine, this is slow.

However, I don't see an easy way to avoid it except to use a totally different type of queue, which would probably mean a total redesign of this library.

I am fine to live with the current situation, since QueuedMails are deleted after sending, so the table never grows huge. It's just slow.

If you have any ideas on how to speed that, though, I'd be open to discussion and implementations.

Constantly growing finished_mails table

After sending, each email goes into the finished_mails table via the FinishedMail model. This table constantly grows. It is currently used for some simple "open" tracking and for unsubscribe purposes.

It also did contain the full interpolated unique body text, but at one point I added an option to not store these texts as the table quickly grew pretty huge.

This is not enough, though, and I'd like the option to not save any records in the finished_mails table at all.

I think it is possible by:

Not storing finished mails in the DB will mean no constantly and quickly growing tables even if one sends lots of emails daily. This is my top priority.

Other notes

There are some other options which could also be made configurable (e.g. Smailer::BOUNCES_PREFIX and some other salts). These are of low importance, though.

Lots of the code can be refactored, simplified and generally improved. I'm also open to PRs related to that if you feel in the mood for it :)

j-a-m-l commented 9 years ago

I share some of your observations. I'll be recolecting new observations and creating issues about them.