1

I'd like to make a commenting thread like stackoverflow does on each Q&A page. The issue I see is how to notify each subscriber (questioner, answerers, commenters) of a new comment allowing them each the ability to mark the comment as read.

I see 2 general solutions:

  1. Make a row for each subscriber, replicating the actual comment in every one of these rows. This would allow a field in each row for each subscriber to mark the comment as read (eliminating it from the little red circle at the top of the page).
  2. Only have 1 row for each comment. The subscribers would be lumped in a single field and there would have to be some complex queries to SELECT and UPDATE whether each subscriber has marked the comment as read.

Maybe there is a better way?

Here's a generic schema show the 2nd approach so answers can have something to refer to:

Comments table

comment_id user_id question_id     comment       comment_read
1            1          1        good stuff      yes=user_id=1, no=user_id=2, no=user_id=3
2            2          1        bad stuff       yes=user_id=1, yes=user_id=2, no=user_id=3
3            3          1        worse stuff     yes=user_id=1, yes=user_id=2, yes=user_id=3
4            4          2        good question   ...
5            1          2        bad question    ...
4

1 回答 1

2

似乎comment_read列的第二种方法过于密集。如果线程上有一千条评论怎么办?

面对这些类型的问题时,您想从透视角度思考……您将如何最频繁地查询数据?您将需要为此定制架构。您可能会根据登录的用户查询:应该通知用户哪些新评论?

为什么不让它变得简单,除了评论表之外还有一个评论/用户表。

 user_id comment_id is_read
 1       1          yes
 2       1          no
 3       1          no
 1       2          yes
 2       2          yes
 3       2          no
 ...

这样,确定用户未读评论的查询就相当容易了(例如 select where is_read=no and user_id = 1)。从评论/问题的角度来看,获得未读评论列表也很容易。

于 2013-08-24T04:03:36.620 回答