在数据库中指定用户权限的最有效方法是什么?

发布于 2024-10-06 21:05:44 字数 1155 浏览 0 评论 0原文

我有一个应用程序,它以 Facebook 风格的方式将用户与特定组关联起来。

例如:

用户 A 与组 1 和组 2 关联

用户 B 与组 2 和组 4 关联

用户可以为其所属的每个组创建帖子(少量文本)。

我有两种类型的页面:登录用户的主页和每个组的页面。用户的主页显示登录用户所属的每个组中的所有其他用户的帖子。。群组页面显示该群组中每个用户的所有帖子。

我并不是想在这里复制 Facebook,但我能想到的功能上最接近的相似之处是来自 Facebook 上的一位朋友的消息如何显示在您的实时提要页面以及用户的墙上(个人资料页面)上。

在我的应用程序中,我有以下三个模型(伪代码):

class User():
    user_name
    first_name
    last_name

class Group():
    group_name

class Post():
    post_content

在数据库可扩展性和性能方面关联这些数据的最有效方法是什么?

1)将每个帖子与用户关联和一个团体。当用户查看群组时,从 Post 表中选择所有帖子,其中群组 ID = 当前群组。当用户查看自己的主页时,查看该用户属于哪些组并查找属于该组的所有其他用户。然后,提取这些用户的所有帖子。

2) 将所有帖子与用户关联。当用户查看自己的主页时,查看该用户属于哪些组并查找属于该组的所有其他用户。然后,提取这些用户的所有帖子。查看群组页面时,找到属于该群组的所有用户,然后提取与这些用户关联的所有帖子。

3) 创建一个包含 PostID、UserID 和 GroupID 的联接表。查看群组时,找到所有具有 GroupID 的帖子并提取这些帖子。查看登录用户的主页时,找到该用户所属的所有组,然后找到属于这些组的所有用户,然后拉取这些用户的所有帖子。

所有这些解决方案似乎都需要大量额外的工作来提取用户主页的记录。这些选项似乎都不是最佳解决方案。我确信有人有这方面的经验。我预计会有大量帖子,因此我希望数据库能够扩展以支持 X 条记录。

有没有一种方法可以做到这一点更有意义?大公司如何设法做同样的事情并最大限度地减少管理费用?

I have an application that associates users with specific groups in a Facebook-style manner.

For example:

User A is associated with Group 1 and Group 2

User B is associated with Group 2 and Group 4

Users can create posts (small amounts of text) for each group that they belong to.

I have two types of pages: the home page for the logged-in user, and a page for each group. The user's home page shows posts from every other user that is in every group that the logged-in user belongs to. The group page shows all posts from every user that is in that group.

I'm not trying to replicate FaceBook here, but the closest parallel I can think of in functionality is how messages from one of your friends on FaceBook appear on your live feed page and also on the user's wall (profile page).

In my application, I have these three models (pseudocode):

class User():
    user_name
    first_name
    last_name

class Group():
    group_name

class Post():
    post_content

What is the most efficient way to associate these data in terms of database scalability and performance?

1) Associate each post to a user and a group. When a user views a group, select all posts from the Post table where Group ID = current group. When a user views their own home page, see what groups the user belongs to and find all other users that belong to that group. Then, pull all posts from those users.

2) Associate all posts with a user. When a user views their own home page, see what groups the user belongs to and find all other users that belong to that group. Then, pull all posts from those users. When viewing a group's page, find all users that belong to that group and then pull all posts associated with those users.

3) Create a join table that has PostID, UserID, and GroupID. When viewing a group, find all posts that have GroupID and pull those posts. When viewing the logged-in user's home page, find all groups the user belongs to and then find all users that belong to those groups and then pull all posts for those users.

All these solutions seem to require a lot of extra work to pull records for the user's home page. None of these options seem like the best solution. I'm sure someone has experience with this. I expect a large volume of posts, so I want the database to be scalable to support X number of records.

Is there a way to do this that makes more sense? How do the big companies manage to do the same thing and minimize their overhead?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瑕疵 2024-10-13 21:05:44

您还没有说明您拥有哪些数据库管理系统。

对于内置安全(权限)系统的 ISO/IEC/ANSI SQL 数据库,您不需要这些,只需使用 SQL 工具设置权限即可。它是内部的并且非常快。

如果您想要性能、可扩展性和数据完整性,您需要放弃对象和类的想法,并了解一些有关关系数据库的知识。此外,如果您将数据建模为关系数据库(而不是对象类),则上述 90% 的问题将不存在。

如果您不明白我在说什么,请阅读此 最近帖子(从2010年12月11日标题开始)。

有没有一种更有意义的方法?大公司如何设法做同样的事情并最大限度地减少开销?

是的,绝对如此。这没有道理。有意义的是对数据进行正确建模,因为标准化模型总体上要快得多。这会导致更多、更小的表,而不是更少的胖表;算术和物理定律起作用。没有数据重复意味着没有更新异常,这意味着事务更小并且不太可能阻塞(您确实希望允许多个用户并发访问,对吗?)。

此外,您的编码也会受到阻碍,因为您无法弄清楚数据与其他数据之间的关系。将您的实体(所有页面的数据内容)放入您的问题中(编辑它并添加到它),我们就可以尝试一下。我可以看到UserGroupPost,但是Wall呢?任何其他家具; 照片相册

You have not stated which dbms you have.

With an ISO/IEC/ANSI SQL database, which has a security (permissions) system built in, you need none of that, just set permissions using the SQL facility. It is internal and very fast.

If you want performance, scalability, and data integrity, you need to give up the idea for objects and classes, and learn a little about Relational databases. Further to that, if you model your data as a Relational database (not as object classes), 90% of your questions above will not exist.

If you do not understand what I am saying, read this recent post (starting from the 11 Dec 10 heading).

Is there a way to do this that makes more sense? How do the big companies manage to do the same thing and minimize their overhead?

Yes, absolutely. It does not make sense. What makes sense is to model the data properly, because a normalised model is much faster overall. This results in more, smaller tables, rather than fewer fat tables; the arithmetic and the laws of physics work. No data duplication means no Update Anomalies, which means transactions are smaller and less likely to block (you do want to allow multiple user concurrent access, right ?).

Besides, your coding will be hindered, beacuse you can't figure out how the data relates to other data. Throw your entities (the data contents of all your pages) up in your question (edit it and add to it), and we can have a go. I can see User,Group,Post, but what about Wall; any other furniture; Photos,Albums.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文