[英]notification system - read vs write
I have thought about two types of user notification systems . 我考虑过两种类型的用户通知系统。
Both of them has a subscriptions table, where users subscribe to a particular channel. 他们两个都有一个订阅表,用户可以在其中订阅特定的频道。
Below schema is for the table that stores events. 架构下方是用于存储事件的表。
When something new happens: 发生新情况时:
|id| |type| |uid| |read| |created|
1 2 2 0 1234
This system , inserts a new row for every user subscribed to a channel when something new happens in that channel. 当该频道中发生新情况时,此系统会为订阅该频道的每个用户插入新行。
Drawbacks: 缺点:
Advantages: 好处:
When something new happens: 发生新情况时:
|id| |type| |created|
1 2 1234
In this system, it inserts only one row for one event ie it is not specific to a user . 在此系统中,它仅为一个事件插入一行,即它不是特定于用户的。 The user then reads the table and checks if that event happened is in his subscribed channel and then also compares if the created time is greater than last read time .
然后,用户读取表并检查该事件是否发生在其订阅的频道中,然后还比较所创建的时间是否大于上次读取时间。
Drawbacks: 缺点:
Advantages: 好处:
Which do you think is better for following conditions: 您认为哪种情况更适合以下情况:
I suggest using a combination of your approaches. 我建议结合使用您的方法。
Have a table with your messages, and then another table associating the per-user status of those messages with the user. 有一个包含您的消息的表,然后有一个表将这些消息的按用户状态与用户相关联。 For instance, your messages table might be as simple as:
例如,您的邮件表可能很简单:
Your other table might have: 您的其他表可能具有:
Then, if you have any other specific information for that user, you can keep track of it outside of the original message. 然后,如果您有该用户的任何其他特定信息,则可以在原始消息之外对其进行跟踪。 If you update that original message, it is still updated for all users.
如果您更新了该原始消息,则仍对所有用户更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.