How could I find out how many users have each email setting?
I’m asking as only about a tenth of users watching a topic are being emailed post notifications.
Thank you.
How could I find out how many users have each email setting?
I’m asking as only about a tenth of users watching a topic are being emailed post notifications.
Thank you.
Os da página de Preferências/E-mails deles? Esse campo está na tabela user_options (email_level), e também existe o de mensagens privadas (email_messages_level).
Acho que este funciona. Ele lista os usuários que estão acompanhando um tópico específico e os conta por nível de e-mail:
| Chave | Nível de E-mail |
|---|---|
| 0 | Sempre |
| 1 | Apenas quando ausente |
| 2 | Nunca |
-- [params]
-- int :topic_id
SELECT tu.topic_id AS topic_id,
uo.email_level,
COUNT(*)
FROM user_options uo
JOIN topic_users tu ON tu.user_id = uo.user_id
WHERE tu.notification_level = 3
AND tu.topic_id = :topic_id
GROUP BY topic_id, uo.email_level
Me diga se eu estraguei tudo. ![]()
![]()
Atualização:
Acho que este também funciona: (e exibe de forma um pouco mais organizada)
-- [params]
-- int :topic_id
SELECT tu.topic_id AS topic_id,
COUNT(CASE WHEN tu.notification_level = 3 THEN 1 END) AS watching,
COUNT(CASE WHEN uo.email_level = 0 THEN 1 END) AS always,
COUNT(CASE WHEN uo.email_level = 1 THEN 1 END) AS only_when_away,
COUNT(CASE WHEN uo.email_level = 2 THEN 1 END) AS never
FROM user_options uo
INNER JOIN topic_users tu ON tu.user_id = uo.user_id
WHERE tu.notification_level = 3
AND tu.topic_id = :topic_id
GROUP BY topic_id