fix digest sending logic
Current issues I think there are serious issues with how we are trying to send digests:
- We loop over all users with sleep 1 in between. After 40 minutes we mark all pages as digest_send. However within these 40 minutes some pages may have changed that the first users would miss.
- We run this every hour - we look at digests for a whole day but my suspicion is this would send out mails every hour if anything changed.
-
I did not see anything that prevents empty updates from being send- we're checking in Mailer::PageHistories#mail if there are histories to send out.
Possible Alternative I think we need to keep track of when we last send a digest per user not per page. The logic could be something like this... If a user has not seen a digest in more than a day... and pages they are watching have changed within the last 24 hours and we determine now is a good time to send a digest... We send out that digest and remember that the user received a digest at that time. That way we can prevent double sending page notifications because we check the user has not received a digest in the last 24 hours and only include changes from those.
When to send digests
The easiest obviously would be to send all digests at a given time of the day. However it would be nice to distribute the load and most people collaborate within their timezones. So at some point people stop changing pages one is watching and go to bed. That would be a good time to send the daily digest.
So my first take on this would be sending the daily digest...
- at most every 24 hours
- when there was something to notify about within the last 24 hours
- one hour after the last page updated occured and at most 23 hours after the first (so we would miss it if we do not send the digest now).
This logic seems fairly complex - maybe there is something more simple. I think it has some nice properties though:
- If I have not received digests in a while and you update a page and walk away i will receive a digest two hours from now.
- If lot's of people update pages I will receive a digest every day at round about the same time.
- If nothing happens for some time after the last digest was send the next one may be delayed a bit to allow for including more edits that happened in a row.
But maybe it's better for users to know ... this is the digest for day x and this is for day y - and not this is for the 24 hours leading up to the time the mail was send.