简体   繁体   English

通知系统-读写

[英]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. 架构下方是用于存储事件的表。

1. Expensive write 1.昂贵的写

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: 缺点:

  • If there are 1 million users subscribed to a channel, you will have to insert 1 million rows for every new thing that happens in the channel. 如果有100万用户订阅了该频道,则必须为该频道中发生的每个新事件插入100万行。
  • Waste of space, duplicate content if not properly normalized 浪费空间,如果未正确归一化,则重复的内容

Advantages: 好处:

  • Fast read times 快速阅读
  • Simple implementation 实施简单

2. Expensive read 2.昂贵的阅读

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: 缺点:

  • Expensive read, since the user has to do lot of filtering . 昂贵的读取,因为用户必须进行大量过滤。
  • User specific events cannot be easily handled [eg. 用户特定的事件无法轻松处理(例如, reply to your comment] 回复您的评论]
  • Complicated implementation when user specific events come in the picture. 当用户特定事件出现时的复杂实现。

Advantages: 好处:

  • Less space required 所需空间更少
  • One to one inserts for events ie less insertion time. 一对一插入事件,即减少插入时间。

Which do you think is better for following conditions: 您认为哪种情况更适合以下情况:

  1. The events can happen (ie writing) 5 to 10 times in a day. 这些事件一天可能发生5次至10次(即写作)。
  2. New events are checked (ie reading) happens every minute for each user. 每位用户每分钟都会检查一次新事件(即阅读)。

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: 例如,您的邮件表可能很简单:

  • id ID
  • message (varchar/text) 消息(varchar /文本)

Your other table might have: 您的其他表可能具有:

  • id ID
  • message_id MESSAGE_ID
  • user_id 用户身份
  • read (boolean) 读取(布尔值)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM