构建Wall系统的数据库/Schema结构
我一直在研究如何用 PHP 构建一个类似于 FB 的墙系统。
我们计划使用 ODM(Mandango、MongoDB)而不是常规 ORM (MySQL) 来实现这一点。一些朋友告诉我有关收件箱/发件箱系统。
- 收件箱是朋友在您的墙上发布的所有消息
- 发件箱是您发布的所有消息
为什么?因为如果您关注某个用户,情况会更简单,您只需关注他的“发件箱”,
每次我在墙上发布内容时,此消息都会复制给我的每个关注者(这将产生大量数据)。 但是当朋友评论我的帖子时该怎么办?他将在哪个实体上评论我的帖子?我的还是他的(因为内容重复)?
你怎么认为 ? 这样的问题你有没有想过?你有答案吗? 谢谢
I've been doing some researches about how to build a wall system similar to FB in PHP.
We planned to use an ODM (Mandango, MongoDB) instead of a regular ORM (MySQL) to achieve this. Some friend told me about inbox/outboxes system.
- Inbox are all the messages that friends posts to your wall
- Outbox are all the message you post
Why that ? Because it'll be simplier if you follow an user, you'll follow only his "outbox"
Each time i'll post something to my wall, this message will be duplicated to each of my followers (which will generate a lot of data).
But what about when a friend comments my post. On which entity is he going to comment my post ? Mine or his (because the content is duplicated) ?
What do you think ?
Have you already thought of this kind of question ? Have you any answers ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这与您如何设置数据库有关。我对 MySql 的经验有限,所以我的回答与此相关。在这种情况下,我至少会有这三个表:
-用户(具有与每个用户关联的唯一ID)
-消息:这包括“收件箱”和“发件箱”消息。您可以将它们全部放在一个表中的原因是,如果您关注某人,它只会提取那些具有(这是一次列)“原始用户 ID”和(这可能是另一列)“接收用户”的消息id”或类似的东西。你如何处理数据都可以用 php 或 asp 或你拥有的东西来完成。
-评论:这包含所有帖子的所有评论,并包含与其相关的消息的唯一 ID 的列。
开发系统时要记住的一件事是您永远不想重复数据。因此,当您在墙上发帖时,您并不希望在数据库中为所有关注您的人创建重复的消息,您希望 php 为您处理传播该信息。
This is all about how you set up your database. I only have limited experience with MySql, so my answer relates to that. In this situation I would have at least these three tables:
-Users (with a unique id associated with each one)
-Messages: this includes both "inbox" and "outbox" messages. The reason you can put them all in one table is because if you're following someone, it will only pull those messages that have the (this is once column) "originating user id" and (this could be another column) "receiving user id" or some such thing. How you handle the data would all be done with php or asp or what have you.
-Comments: this holds all comments for all posts, and includes a column for the unique id of the message it relates to.
One thing to keep in mind when developing your system is that you never want to duplicate data. So, when you post to your wall, you don't want to actually create duplicate messages in your database for all the people who are following you, you want php to handle disseminating that information for you.