If a user does not submit the digest settings form on her profile, she'll get no digest emails.

On a site with 2 users, with only the second user explicitly subscribed and having an entry in {digests}, if the preliminary query in _digests_cron() is SELECT d.*, u.* /* We need the digests table first here, otherwise users with no digests row have uid = NULL in the results */ FROM users u LEFT JOIN digests d ON u.uid = d.uid WHERE status = 1 ; then we get 2 user results. However, if we take the whole conditional,

SELECT d.*, u.* /* We need the digests table first here, otherwise users with no digests row have uid = NULL in the results */ FROM users u LEFT JOIN digests d ON u.uid = d.uid WHERE status = 1 AND ( /* user is not blocked */ send_interval IS NULL OR /* user has not set their interval */ send_interval = 86400 /* user's interval is daily */ /* user's interval is weekly, and it's Sunday */ ) AND 1314123699 > COALESCE(last_sent, created) + (COALESCE(send_interval, 86400) - 43200) /* it's been at least (interval - 12 hours) since the last digest email */ AND ( 1314123699 /* NOW */ > 1314075600 /* SEND */ + timezone OR /* it's after send_time today */ 1314123699 /* NOW */ < 1314075600 /* SEND */ + timezone - 43200 /* it's more than 12hrs before send_time today, i.e. less than 12hrs since send_time yesterday */ OR timezone IS NULL /* the user has not set a timezone, fall back to the site default */ ) LIMIT 0, 250

Then we only get 1 result, and it's the user who has an entry in {digests}:

Sidenote, the query comments, while helpful, make the actual query harder to read. Could be better to have them not appear inline in the query.

Comments

ezra-g’s picture

Issue tags: +Commons release 2.0

Adding commons release tag.

icecreamyou’s picture

I don't know how you're retrieving that query, but it's executed with appropriate line breaks and whitespace so that the comments should actually be helpful.

Query looks right to me. All the columns in the digests table have OR IS NULL or COALESCE() checks so that they're not required. Not sure what would cause the problem you're experiencing. I would break that conditional apart and try running each part of it manually to see which part causes only 1 user to be returned.

ezra-g’s picture

Status: Active » Needs review
StatusFileSize
new2.42 KB

Here's an attempt at resolving this.

I discussed a bit in IRC with greggles, and he provided helpful feedback as well.

ezra-g’s picture

StatusFileSize
new2.41 KB

Here's a revision with a slightly more sane send interval ;).

ezra-g’s picture

Status: Needs review » Needs work
StatusFileSize
new8.71 KB

Here's an in-progress patch for discussion on IRC.

icecreamyou’s picture

Status: Needs work » Postponed (maintainer needs more info)

I can't reproduce this issue, but I think I've figured out #1256732: Daily email summaries are not being sent at the correct time of day.

ezra-g’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

We had trouble reproducing this as a team.