我使用了一个数据探索器查询来找出在 user_actions 中参与了某个主题的用户:
-- [params]
-- int :topic = 3620561
select user_id,
sum(action_type) actions,
sum(case action_type when 5 then 1 else 0 end) replies
from user_actions ua
join users u on u.id = ua.user_id
where target_topic_id = :topic
and moderator is false
and admin is false
group by ua.user_id
这包括了回复、点赞、编辑和提及等操作。我还有一个包含投票响应的查询。这是为了收集潜在客户,但我认为除了回复之外还做了一些事情的人可能对该主题有要求。“参与”的定义可能是一个有用的练习。
要扩展到整个类别,请与 topics t on target_topic_id = t.id 连接,并在 where 子句中添加 category_id。根据 ua.created_at 定义时间范围应该不难。