通知系统中每个通知要插入几行? [英] How many rows to insert per notification in a notification system?

查看:56
本文介绍了通知系统中每个通知要插入几行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是这个问题,我正在构建一个类似的通知系统,一个问题(我认为答案很明显,但我希望有其他意见):

Following on from this question I am looking at building a similar notification system and I have a question (which has an obvious answer I think but I'd prefer to have some other opinions):

如果某个特定帖子产生了100万个赞,然后有人在该帖子中添加了评论,则我需要通知喜欢该帖子的那百万人有关所添加评论的信息.实现此目的的唯一方法是将一百万行写入具有 NotificationID NotificationRead 表并将其发送"给各个用户吗?

If a particular post generated a million likes, and then someone adds a comment to that post, I would need to notify those million people who liked the post about the comment that was added. Is the only way to achieve this to write a million rows into a NotificationRead table which has the NotificationID and 'send' them to the various users?

我无法想象任何其他方法可以让我跟踪谁阅读了他们的通知,并可能在每个通知的每个帖子中插入一百万行,这听起来既艰巨又昂贵.

I can't visualise any other approach that would let me keep a track of who read their notifications and potentially inserting a million rows per post per notification sounds daunting and expensive.

还有其他方法可以做到吗?我正在使用SQL Server 2014,而我的应用程序服务器是ColdFusion 2016

Is there any other way to do it? I am using SQL Server 2014 and my application server is ColdFusion 2016

推荐答案

首先,如果您需要推送通知,则不可避免地需要以某种方式通知百万用户.但是,您不一定需要将所有通知都存储在服务器上.

First off, if you need push notifications, there's no escaping the fact that you need to somehow notify each of the million users. However you don't necessarily need to store all the notifications on your server.

可以做出一些合理的假设:

One could make some reasonable assumptions:

  • 大多数活动将发生在最近的帖子上(例如,少于一周的帖子)
  • 大多数用户不会立即回复通知

这样,您可以跳过为最近的帖子存储通知的操作:当用户登录时,您可以简单地轮询用户的最近的帖子以查看是否有任何新活动.用户登录时,您正在做额外的工作,但这会随着时间的流逝而分散.

With this, you can skip storing notifications for recent posts: when a user logs in, you can simply poll the user's recent posts to see if there is any new activity. You're doing extra work when the user logs in but this is spread over time.

对于较早的帖子,您仍然会退回去为每个用户存储单独的通知,但这不应该经常发生.同样,您可以选择保留每个用户的最后N个通知列表,而不是为每个通知插入新行.这样,如果用户很长一段时间未登录,则您不会堆积旧的通知(该用户可能无论如何都不在乎).

For older posts, you would still fall back to storing individual notifications for each user, but this shouldn't happen often. Here again, instead of inserting a new row for each notification, you could choose to keep a list of the last N notifications per user. That way, if a user doesn't log in for a long time, you're not piling up old notifications (that the user probably doesn't care about anyway).

这篇关于通知系统中每个通知要插入几行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆