关于构建评论系统的建议

发布于 2024-10-22 08:52:20 字数 305 浏览 1 评论 0原文

我是数据库设计的初学者,我想创建一个评论系统,能够回复用户评论并显示用户所做的所有评论。此外,将会有很多页面,每个页面都有一个用于评论的部分。

到目前为止,我已经提出了两种潜在的数据库设计来构建评论系统。第一个将有一个用于每个页面评论的表格和一个用于每个用户评论的表格。页面评论表将具有用于表链接目的的 user_id 和 page_id 字段。

第二个潜在的设计结构是拥有一个大型评论分区表,其中仅包含用于表链接的 comment_id 和 user_id 字段。我还没想好如何实现回复功能;在解决这个问题之前,我想了解哪种设计方法(如果有的话)可以有效地执行。

I am a beginner at database design and I would like to create a comment system with the ability to reply to user comments and to display potentially all comments a user has made. Furthermore, there will be many pages that will each have a section for commenting.

So far I have come up with two potential database designs to structure the comment system. The first will have a table for each pages' comments and a table for each users' comments. The page comment table will have user_id and page_id fields for table linking purposes.

The second potential design structure is to have one large partitioned table of comments that just has comment_id and user_id fields for table linking. I haven't thought about how to approach the reply feature yet; I wanted to get some input on which design approach, if any, would perform efficiently before I tackled that problem.

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

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

发布评论

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

评论(2

江心雾 2024-10-29 08:52:20

我会使用两张表:一张用于评论线程,另一张用于评论。评论线程看起来像这样:

id
/* Other bookkeeping things like created time and such */

和 comments:

id
thread_id
user_id
comment
parent_id
/* Other bookkeeping stuff */

然后通过向页表添加 comment_thread_id 列将线程附加到页面。

拥有单独的不同注释线程可以让您在将来方便地附加访问控制或类似的扩展,它还允许您将注释线程附加到事物上。将评论线程附加到页面而不是相反,这样以后就可以轻松地将评论线程添加到系统中的其他对象。

I'd go with two tables: one for comment threads and another for the comments. The comment threads would look something like this:

id
/* Other bookkeeping things like created time and such */

and comments:

id
thread_id
user_id
comment
parent_id
/* Other bookkeeping stuff */

Then attach the thread to the page by adding a comment_thread_id column to the page table.

Having a separate distinct comment thread gives you a convenient place to attach access control or similar extensions in the future, it also allows you to attach comment threads to things. Attaching the comment threads to the page rather than the other way around makes it easy to add comment threads to other objects in your system later on.

屌丝范 2024-10-29 08:52:20
comments
   id
   user_id
   comment_text
   page_id
   parent_id

使用它来存储页面的评论。 parent_id 是一条评论,是另一条评论的回复。对于页面上的评论,parent_id 将为零(无父评论),但对于回复,parent_id 将非零,并且它将是回复所属评论的 ID。

例如,您将拥有这样的数据

id user_id comment_text page_id parent_id
1  6         sdh          1       0          <-- comment on the page
2  9         gfdf         2       0          <-- another comment on other page
3  4         reply xzy    1       1          <-- reply to comment id 1 by user id 4 on page 1

您可以考虑使用 timestampflaaggeddeleted 等字段来帮助您排序、排序、过滤、监控和软删除评论。您可以按页面、按用户、按父级进行分组。

comments
   id
   user_id
   comment_text
   page_id
   parent_id

Use this to store comment for a page. parent_id is a comment that is a reply of another comment. For a comment on the page the parent_id will be zero (no parent comment), but for a reply the parent_id will be non-zero and it will be the ID of the comment which the reply belongs to.

For example, you will have data like this

id user_id comment_text page_id parent_id
1  6         sdh          1       0          <-- comment on the page
2  9         gfdf         2       0          <-- another comment on other page
3  4         reply xzy    1       1          <-- reply to comment id 1 by user id 4 on page 1

You may consider having timestamp, flagged, deleted etc fields that can help you in sorting, ordering, filtering, monitoring and soft-deleting a comment. You can group by page, by user, by parent.

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