简体   繁体   English

实时创建新闻提要

[英]Creating a news feed realtime

I have a database containing many tables : [followers, favorites, posts ...etc) 我有一个包含许多表的数据库:[关注者,收藏夹,帖子等

These tables define the different activities a user can achieve, he can send posts, add other people to favorites and follow others. 这些表定义了用户可以实现的不同活动,他可以发送帖子,将其他人添加到收藏夹并关注其他人。

What I want to do.. is to extract data from these tables, and build a real-time news feed . 我想做的是从这些表中提取数据,并建立一个实时新闻提要。

I have two options: 我有两个选择:

1- Creating a separate table for the notifications (so that I won't have to get data from multiple tables, then using a Javascript timer to return results every x seconds. 1-为通知创建一个单独的表(这样我就不必从多个表中获取数据,然后使用Javascript计时器每x秒返回一次结果。

2- using XMPP server...that sends (or pushes) notifications every x second, without actually sending any ajax queries. 2-使用XMPP服务器...每隔x秒发送(或推送)通知,而不实际发送任何ajax查询。

And for these two options, I don't know whether I should connect to these tables to get news feed, or just create a separate table for notifications. 对于这两个选项,我不知道是否应该连接到这些表以获取新闻提要,还是只为通知创建一个单独的表。

I searched in the subject, but I didn't find something really helpful yet, Any links will be appreciated. 我搜索了该主题,但还没有发现真正有用的东西,所有链接将不胜感激。

If your data is normalized , you should be able to pull all the data with one query (using JOINs), or you could try creating a View if you want to query from one table. 如果您的数据已规范化 ,则您应该能够使用一个查询(使用JOINs)提取所有数据,或者如果您想从一个表中查询,则可以尝试创建一个View It's always best to keep your data in the appropriate tables to avoid having to duplicate data. 始终最好将数据保存在适当的表中,以避免重复数据。

The push notifications are easier on the server, since they're not receiving requests from each client. 推送通知在服务器上更容易,因为它们没有收到每个客户端的请求。 Depending on your load, you could probably get away with simple AJAX requests. 根据您的负载,您可能可以摆脱简单的AJAX请求。

The request for news feed will be very frequently. 对新闻提要的请求将非常频繁。 So you must keep your code run fast and take as less resource ( CPU-time , database query ) as possible. 因此,您必须保持代码快速运行,并占用尽可能少的资源( CPU-timedatabase query )。

I suggest you to take the first option. 我建议您采取第一个选择。 It meets your requirement and is simple enough. 它满足您的要求并且非常简单。

Because you have many tables, all of them will grow bigger day by day . 因为您有很多桌子,所以它们都会grow bigger day by day Every time you connect them to get news feed will take a long time and increase the load of your database. 每次将它们连接到新闻源时,都会花费很长时间,并增加数据库的负载。 In the other hand, you query sql will be complex. 另一方面,您查询sql会很复杂。

Like @Curtis Mattoon said: avoid having to duplicate data , but sometime, we need spend more space for less time . 就像@Curtis Mattoon所说: avoid having to duplicate data ,但是有时候,我们需要spend more space for less time

So I suggest to create a new table to store the notification data. 因此,我建议创建一个新表来存储通知数据。 You even can delete the old data from this table periodically. 您甚至可以定期从该表中删除旧数据。

At the same time, your sql and php code for news feed will be simple and run fast. 同时,用于新闻提要的sql和php code将变得简单且运行迅速。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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