duandai3964 2015-01-13 11:37
浏览 45

如何在Feed中对通知进行分组

I'm implementing a feed in it some notifications should be displayed as a group (i.e. a user posted a comment on your video) and others as standalone notifications (Your video is featured this week). Highlighting new notifications is also a requirement

For grouped notifications, when the user consult his feed the entry should be something like

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

The problem is how to group the events when the notifications are interleaved.

In example, imagine the following log:

 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

The feed coud be grouped in several ways. Even new notifications may alter the groups breaking the highlighting.

Where can I read more about common solutions for this problem and how to store and return the notifications for my web service?

  • 写回答

1条回答 默认 最新

  • dqxyh48864 2015-02-09 17:23
    关注

    Personally, I would record the notifications times precisely, and then do something like this (I have not tested these specific solutions, but have done similar things previously):

    If you wanted notifications to be grouped by date:

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

    By hour (with subdivision boundaries relative to current time), you might do this:

    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);
    

    For notifications grouped in other ways, I would write a suitable formula in the GROUP BY clause.

    For the indication of who last commented, I would do something like this:

    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;
    

    I've used the MySQL-specific GROUP_CONCAT() function here, with the string function SUBSTRING_INDEX: Some alternative techniques for solving this problem with a JOIN/aggregate may be difficult to perfect because MySQL apparently does not support LIMIT within a subquery. You might need to consider the format of your commenter_id, commenter_name or equivalent field(s); when adapting my solution.

    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?