'追随者'和效率[英] 'Followers' and efficiency

本文是小编为大家收集整理的关于'追随者'和效率的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

从Twitter意义上讲,我正在设计一个将涉及用户"跟随"彼此活动的应用程序,但是我对数据库/查询设计/效率的经验不太经验.是否有用于管理此问题的最佳实践,要避免的陷阱等?我收集的话,如果不正确完成(或者甚至可能?).

,可以在DB上产生很大的负载.

如果有所作为,人们可能只会"跟随"相对较少的人(但一个人可能有很多追随者).但是,这是不确定的,我不想指望它.

感激不尽收到的任何建议.谢谢.

推荐答案

完整归一化非常简单易用.如果您有一个用户表,每个用户表都有唯一的ID,则将具有带有列的TABLE_FOLLOWERS表,USERID和FOLLOWERID将每个用户的所有追随者描述为一对一的一对一关系.

即使在半个不错的数据库服务器上进行数百万个分析,只要您使用良好的数据库(即,而不是MS-ACCESS),也会运行良好.

其他推荐答案

模型非常简单.问题在于订阅表的大小;如果有100万用户,并且每个用户订阅为1000,则订阅表有10亿行.

 follower_model.png

其他推荐答案

取决于您期望需要多少用户;您期望用户有多少关注者;如果您对先前问题的回答证明是乐观的,您期望有什么样的资金/开发效果.

对于一个小型项目,我可能会忽略数据库,将应用程序设计为具有维护List[followers]对象的简单对象模型.将其全部保留在RAM中以进行正常操作,并使用ORM定期持续到数据库(可能是PostgreSQL或MySQL).

对于一个较大的项目,我根本不会使用关系数据库;但是我将使用的确切使用将取决于项目的具体细节.

如果您只是想刺激这个概念,请采用ORM方法;但是,请记住它不会扩展.

本文地址:https://www.itbaoku.cn/post/597565.html

问题描述

I am designing an app that would involve users 'following' each other's activity, in the twitter sense, but I am not very experienced with database/query design/efficiency. Are there best practices for managing this, pitfalls to avoid, etc.? I gather this can create a very large load on the db if not done properly (or maybe even then?).

If it makes a difference it is likely that people will 'follow' only a relatively small number of people (but a person may have many followers). However this is not certain, and I wouldn't want to count on it.

Any advice gratefully received. Thanks.

推荐答案

Pretty simple and easy to do with full normalisation. If you have a table of users, each with a unique ID, you would have a TABLE_FOLLOWERS table with the columns, USERID and FOLLOWERID which would describe all the followers for each user as a one to one to many relationship.

Even with millions of assosciations on a half decent database server this will perform well and fast as long as you are using a good database (IE, not MS-Access).

其他推荐答案

The model is fairly simple. The problem is in the size of the Subscription table; if there are 1 million users, and each subscribes to 1000, then the Subscription table has 1 billion rows.

follower_model.png

其他推荐答案

That depends on how many users you expect to need to support; how many followers you expect users to have; and what sort of funding/development-effort you expect to have access to should your answers to the previous questions prove optimistic.

For a small scale project I would likely ignore the database, design the application as a simple object model with User objects that maintain a List[followers]. Keep it all in RAM for normal operation and use an ORM to persist to a database periodically (probably postgresql or mysql).

For a larger project I would not be using a relational database at all; but exactly what I would use would depend on the specific details of the project.

If you are only trying to spike the concept, go with the ORM approach; but, keep in mind it won't scale.