gpt4 book ai didi

php - 如何在提要中对通知进行分组

转载 作者:搜寻专家 更新时间:2023-10-31 22:01:39 30 4
gpt4 key购买 nike

我在其中实现了一个提要,一些通知应显示为一个组(即用户对您的视频发表了评论),而其他通知应显示为独立通知(您的视频本周有特色)。突出显示新通知也是一项要求

对于分组通知,当用户查阅他的提要时,条目应该类似于

Joe and other 5 posted a comment on your video "Cooking with fire"

问题是当通知交错时如何对事件进行分组。

例如,假设有以下日志:

 1 min ago           Joe posted comment on video 1
10 mins ago Video 1 featured
11 mins ago Helen posted comment on video 1
11 mins ago Michael posted comment on video 1
14 mins ago David posted comment on video 1
14 mins ago Robert posted comment on video 1

提要可以通过多种方式进行分组。即使是新通知也可能会改变突出显示的组。

我在哪里可以阅读更多关于此问题的常见解决方案以及如何存储和返回我的网络服务的通知?

最佳答案

就我个人而言,我会准确地记录通知时间,然后做这样的事情(我没有测试过这些具体的解决方案,但之前做过类似的事情):

如果您希望通知按日期分组:

SELECT about_resource_id,DATE(notification_time) AS notification_date,COUNT(*) FROM notification_tbl GROUP BY about_resource_id,DATE(notification_time);

按小时(具有相对于当前时间的分割边界),您可以这样做:

SELECT 
about_resource_id,
TIMESTAMPDIFF(HOUR,NOW(),notification_time) AS hours_ago,
COUNT(*)
FROM notification_tbl
GROUP BY about_resource_id,TIMESTAMPDIFF(HOUR,NOW(),notification_time);

对于以其他方式分组的通知,我会在 GROUP BY 子句中写一个合适的公式。

为了表明最后评论的人,我会做这样的事情:

SELECT 
about_resource_id,
DATE(notification_time) AS notification_date,
SUBSTRING_INDEX(GROUP_CONCAT(counterparty_id,";"),";",1) AS last_commenter_id,
COUNT(*) AS commenters
FROM notification_tbl
GROUP BY
about_resource_id,
DATE(notification_time)
ORDER BY notification_time DESC;

我在这里使用了 MySQL 特定的 GROUP_CONCAT() 函数和字符串函数 SUBSTRING_INDEX: Some alternative techniques for solving this problem with a JOIN/aggregate可能很难完善因为MySQL apparently does not support LIMIT within a subquery .您可能需要考虑您的 commenter_id、commenter_name 或等效字段的格式;在调整我的解决方案时。

关于php - 如何在提要中对通知进行分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27921279/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com