我想获取昨日点赞或者浏览量,前10的帖子,有什么办法可以得到吗,似乎数据库存储的都是累计值,谢谢
Hey
Do you have the Discourse Data Explorer plugin enabled on your site?
没有启用呢,是不是需要启用 才会记录更详细的数据
You should enable it, then you’ll be able to make specific queries scoped to the past day (yesterday).
Query for Top 10 Posts by Likes from Yesterday
-- Top 10 Posts by Likes from Yesterday
WITH yesterday_actions AS (
SELECT
post_id,
COUNT(*) AS like_count
FROM post_actions
WHERE
created_at::date = CURRENT_DATE - 1
AND post_action_type_id = 2 -- Like action type
GROUP BY post_id
)
SELECT
p.id AS post_id,
t.id AS topic_id,
t.title AS topic_title,
p.post_number,
u.username AS author,
ya.like_count AS likes_yesterday
FROM yesterday_actions ya
JOIN posts p ON p.id = ya.post_id
JOIN topics t ON t.id = p.topic_id
JOIN users u ON u.id = p.user_id
ORDER BY likes_yesterday DESC
LIMIT 10
Query for Top 10 Posts by Views from Yesterday
-- Top 10 Topics by Views from Yesterday
WITH yesterday_topic_views AS (
SELECT
topic_id,
COUNT(*) AS view_count
FROM topic_views
WHERE viewed_at::date = CURRENT_DATE - 1
GROUP BY topic_id
)
SELECT
t.id AS topic_id,
t.title,
u.username AS creator,
ytv.view_count AS views_yesterday
FROM yesterday_topic_views ytv
JOIN topics t ON t.id = ytv.topic_id
JOIN users u ON u.id = t.user_id
ORDER BY views_yesterday DESC
LIMIT 10
(generated using AI bot!)
1 Like