New comments for introducing website notifications

I have a website where people can write and comment on them. I want to create a notification system for new comments, so when a user logs in, he can see the number of new comments to his posts.

My idea is to add a “read” table where I will store user_id and comment_id (means that user_id reads comment_id). But this can cause some performance problems as the table grows.

What is the best way to implement this?

+3
source share
4 answers

One way to achieve this is simply to save the created date for publication and comments, as well as the date of the "last visit" for the user (or "the last time the user clicks the" show me a new entry "link).

Then you just need to get all the message and comment that have a newer date than the one you find in the user table.

+4
source

How to just save user IDs and comments for unread comments? Then, when the user reads the comment, you can delete this row from the table.

+3
source

, ( ). :

$lastActivityTime = User->GetLastActivity();
$result = mysql_num_rows(mysql_query("SELECT COUNT(`id`) FROM `notifications` WHERE `postTime` > '$lastActivityTime'"));

!

0

, mySQL (: MongoDB).

Or you can make a pub / sub implementation to notify users. (With pubsub you don't need to store data. Just let me know)

0
source

All Articles