views:

36

answers:

4

I want to allow my users to opt-out of certain email notifications. I'm trying to decide how to implement this in the database. I've already got a set of Users and all the emails are stored as EmailTemplates which have a unique key. So I figure a simple m2m table with users/emails would work well.

However, should I (1) populate this table with all user/email combinations every time a user is created (may complicate things when a new email is added?) so that by default they're opted into everything, or should I (2) do it backwards and say if there is no entry for this user/email pair do send the email? Then the preferences table kind of becomes a BlockEmailNotification table.

Thoughts?

+1  A: 

In your shoes, I'd go with the BlockEmailNotification table. As you said, it eliminates the overhead of populating the table for every new email template. Also, it will have fewer rows because most people don't exert the extra effort to opt out (or even realize that they can or know how), though the impact that would have on performance depends on how many subscribers you have.

+1  A: 

Maybe a EmailNotificationRules in which you initially store (user_id, 'default'). And (user_id, 'skip mail_1 template') when mail_1 is opt_in by default; or (user_id, 'add mail_1 template') when mail_1 is opt_out by default...

pascal
+1  A: 

I would recommend developing a user preferences framework where "BlockEmail" could be a setting and the setting could contain a collection of ids that should not be sent. During the email generation/preparation, the user's preference would be looked up and email continued or aborted. Having a preference framework would also allow you to extend user configuration capabilities elsewhere.

Joel Etherton
So.... option #2.
Mark
@Mark - maybe more like 2a. I'd say there's a bit more to it than that, but yes that's the general idea.
Joel Etherton
+1  A: 

OTOH, If Jeff M is wrong and your particular users are more savvy and opt out of everything, you'll have more rows than if you had done it the other way.

In these types of questions, I'm not sure if it makes a huge difference where you start AND I'm not sure it would be a huge rewrite to reverse this decision later on.

Ess Oh Hader