2

I'm building a system which has notifications where if a user 'likes' something, the other user gets a notification to let them know and they gain points.

I have an actions table where events are stored, and a flag to say whether it has been read (whether the notification has been read).

Problems arise when a user continuously likes/unlikes the same thing (as people like to do, to break stuff). I don't want to add and subtract every time from the other users points, and I don't want really want to log every event of like and unlike, so I need some form of buffer that waits a while to see whether the end result was an actual like - and then process the event and show the notification.

The likes themselves have timestamps, so I could do something around that, but I wondered whether there is a better way of storing this info into a 'buffer' table and then calculate the end result there? What is the most cost-effective method of doing this?

4

1 回答 1

1

当用户“不喜欢”某些东西时,我会从您的actions表中删除“喜欢”事件,如果此类事件仍处于未决状态。

如果你想实现一些更高级的东西,使用一个缓冲表(也许在内存中,如果你能承受在服务器崩溃的情况下丢失一些事件),它保存最后的事件,比如 10 分钟。这样,您只需处理一个非常小的数据集即可插入和删除。

然后创建一个EVENT将该临时表中超过 10 分钟的记录刷新到您的参考actions表中。

[编辑]

再想一想,我认为我们可以使用幼稚的方法:插入并从唯一的actions表中删除,但在显示通知(或计算“喜欢”的数量)时只考虑早于 [您的阈值] 的记录。

于 2013-07-18T09:46:12.963 回答