开发者

Handling Read/Unread Posts for users like mail in mysql

I need to handle read/ unread s开发者_如何学JAVAtatus of a post per user. Write now i am using a denormalized column to store comma separated user_ids. Since it is a text column the performance of the select query is degraded.

Now i would like to assign a constant for all the users say User A - 1, User B-2, User C-4 and User D-8 (Bitwise), and store its combination in a integer column.So when the user A,C read the value for the integer column will be (1+4) 5. And use the bitwise operator in criteria to query the read/unread post. The problem is the no. of users that i can store as combination is restricted say 62 user's status in a column. If i have to extend further i may have add another BIGINT column to store other users.

What could be the best way to store that information. Following are the action i need to do.

  1. when a new reply is posted then i have to update the value as 0 (to make unread for every one).
  2. Update the status in the column when a user reads the post.
  3. Select all the unread post for an user.

EDIT: I trying to address 3rd action indirectly. i add that integer column in select columns list and find the read status for the user in application code instead of adding as mysql criteria. Any way this is not a solution. I still need of a good one.


I would just do it this way, create a table like this:

CREATE TABLE views(
    user_id bigint not null,
    post_id bigint not null,
    primary key(user_id,post_id
)

and then just check if a record with the user's id and the post id exists. You can also use this to count the number of views.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜