algorithm - twitter 之类的应用程序是如何实现的?

标签 algorithm twitter

假设A关注了100个人,

然后将需要 100 个连接语句,

我认为这对数据库来说太可怕了。

或者还有其他方法?

最佳答案

为什么需要 100 个连接?

您将有一个简单的表“Follows”,其中包含您的 ID 和其他人的 ID...

然后你通过加入这样的东西来检索“推文”:

Select top 100 
    tweet.* 
from 
    tweet 
inner join 
    followers on follower.id = tweet.AuthorID 
where 
    followers.masterID = yourID

现在你只需要一个像样的缓存并确保你使用非锁定查询并且你拥有所有信息......(好吧也许添加一些用户数据到组合中)

编辑:

鸣叫

ID - tweetid
AuthorID - ID of the poster

追随者

MasterID - (Basically your ID)
FollowerID - (ID of the person following you)

Followers 表有一个基于 master 和 followerID 的复合 ID 它应该有 2 个索引 - 一个在“masterID - followerID”上,一个在“FollowerID 和 MasterID”上

关于algorithm - twitter 之类的应用程序是如何实现的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1415147/

相关文章:

java - 在 JRE 中使用什么算法将 ArrayList<T> 转换为 LinkedHashSet<T>

python - 多次尝试后无法访问推特

c++ - 寻找最小的产品

algorithm - 在 MATLAB 中使用 Levenberg-Marquardt (lsqcurvefit) 获取协方差矩阵

security - 为什么要使用 chaffify ID 来为对象创建唯一的 URL?

java - spring-social-twitter,@Value 不连接属性

python - 将 Twitter XML 日期转换为 Python 日期对象

javascript - 我是否阅读了搜索查询中的所有推文

算法帮助 : divide a matrix to N continuous cells, 具有接近相等的项目总和

algorithm - 任何渲染多个实体切割平面的方法?