How to make status unread comments?

Good afternoon.

There is a project in which there are users and there are comments to some entity.

How to make a display of neprochitannoe messages? Ie, for one user the message "A" can be read, and for another, the same message "A" may be unread.

Nothing but the table, unread comments are not periodic (id_comment, id_user)

A project on Yii2.

Thanks in advance.
June 14th 19 at 18:58
5 answers
June 14th 19 at 19:08
And why is everyone trying to write to the database? There are also cookies and in most cases it is sufficient to record the client in a cookie and all. Why ship base?
And where is cookie? We went with another device and that? - Mabel commented on June 14th 19 at 19:11
And he may have multiple accounts etc. etc. there You write - the Washington Post? A majority of users go through one company and under one login. Exceptions - their problem. To write miles of code and strain base because of a handful of informal - is the norm? - Palma_Schamberger commented on June 14th 19 at 19:14
The majority of users are sitting with 2 devices. Just look at the statistics. This was no exception. It's not just comments in any social network, and important messages that one can not miss. - Violet_Wiso commented on June 14th 19 at 19:17
,
So he will not miss. Just be more unread. Compare server load - a single entry in the cookies or shoveling database. I would generally wrote in the cookie machine time and numbers read messages. And then it's checked. Quickly and efficiently. - Palma_Schamberger commented on June 14th 19 at 19:20
you probably do not quite understand the task. It's not just the comments under some posts in the entertainment social network. This is quite an important message. And should not just display their number and to know which message is unread. - Violet_Wiso commented on June 14th 19 at 19:23
And I think you are not familiar with cookies.

setcookie("user", "Gremlin");
setcookie("lastVisit", "time()");
setcookie("readed", "1880, 1780,1665,1546,1455,1766");

And everything!!! Everything older than time() be considered as read, else append to cook readed. Check at all of one line. Thank you. - Palma_Schamberger commented on June 14th 19 at 19:26
conversation with the deaf-blind. - Violet_Wiso commented on June 14th 19 at 19:29
June 14th 19 at 19:00
record the date of the last visit topic and all the comments that were after the date of the last visit considered unread.
Ah, at one time wrote) - Mabel commented on June 14th 19 at 19:03
Bothers me with this approach is that on each page where will these counters (total, separately for each entity), they will be every time counted for, isn't it too much ? - Palma_Schamberger commented on June 14th 19 at 19:06
and what's the problem?
SELECT tipic_id, count(id) FROM comments WHERE date >= <user_last_visit_time> GROUP BY topic_id;</user_last_visit_time>

Or even a left join with a table of locations visited by the user of topics and date. - Violet_Wiso commented on June 14th 19 at 19:09
that is for each user to be stored in a separate table, and the dates of attendance of each of the topics ? - Palma_Schamberger commented on June 14th 19 at 19:12
Yes, a table (user_id, topic_id, date) (If you need info on each topic) - Violet_Wiso commented on June 14th 19 at 19:15
as I suggest (to store in the table unread comments), you can make VC, so you can open up a dialogue, and if you were not on the screen, they will not be read. Too funny thing. - Palma_Schamberger commented on June 14th 19 at 19:18
in the VC all private messages and they lie in the table "messages" (from, to, message, readed=true/false). - Violet_Wiso commented on June 14th 19 at 19:21
I meant the action by which the flag is read or not. - Palma_Schamberger commented on June 14th 19 at 19:24
A R, in VC all private messages and they lie in the table "messages" (from, to, message, readed=true/false).


Interesting , whence such information? What if it's a group chat? - nicklaus.Will commented on June 14th 19 at 19:27
it's a guess. - Violet_Wiso commented on June 14th 19 at 19:30
and what then in the case when you need to display a list of topics, say, 50 rows, in which you need to show read the topic or not (for example, the customer wants to display the list of unread topics in bold), in this case, each record will have at least 2 query to the database, that is already minmum 100 queries - Jack commented on June 14th 19 at 19:33
,
You can use one query to select all the topics, and another to choose where you have unread messages.

PS: it is better to do this already to make a separate question on the Toaster with a description of your current schema. - Violet_Wiso commented on June 14th 19 at 19:36
I didn't ask for advice for yourself. I asked what would You do in this case, again I suggest to make separate queries - Jack commented on June 14th 19 at 19:39
June 14th 19 at 19:02
Statistics on attendance are not maintained?
You can keep track on which pages the user at what time.
Accordingly, to correlate the time of the visit and posting a review.
June 14th 19 at 19:04
By date 100%.
It is cheap relative to disk space.
June 14th 19 at 19:06
Nothing but the table, unread comments are not periodic
(id_comment, id_user)


so how do you suggest I (keep in a plate unread comments), you can make VC, so you can open up a dialogue, and if you were not on the screen, they will not be read. Too funny thing.


Suppose that the system was 100500 users, after adding a new comment you will need to add all the information about the new unread comments? And if the comment is edited? What about new users?

Properly store the view and not "unread comments":

comments
id, user_id, text, ...

comment_views
id, comment_id, user_id, ...
Really, these comments are not taken into account, but this fact does not change. - Palma_Schamberger commented on June 14th 19 at 19:30
No make it wrong. So this database will always grow much more than keep unread comments. - Mabel commented on June 14th 19 at 19:09
Is this a joke? Arguments, please, if You really think so. - Palma_Schamberger commented on June 14th 19 at 19:12
It is not a joke. There are 100 clients and 100 comments, all of them are read by all users. How many records are in the table with unread comments? 0.

Then 1 client, have written 10 posts, nobody read. How many will be records in a table with unread comments ? 100.

Further, all clients have read all of the messages in the table with the unread comments will be back to zero records.

And in your case the table with read reviews will be 11000 records. - Violet_Wiso commented on June 14th 19 at 19:15
This is not a joke. There are 100 clients and 100 comments, all of them are read by all users. How many records are in the table with unread comments? 0.

True, but not everyone reads comments, so in the database will accumulate trash.

Then 1 client, have written 10 posts, nobody read. How many will be records in a table with unread comments ? 100.

Wrong.

Nothing but the table, unread comments are not periodic (id_comment, id_user)


If You are planning such a table: id_comment, id_user, you will need to add entries for each pair "comment - user" and this is a 10*99 = 990 records, unless you consider the author of the review.

Every time a user adds a comment You want to create 99 more records with marks of unread comments? And if it was a new user?

And in your case the table with read reviews will be 11000 records.

Wrong, in the worst case (every user will read all of the comments excluding the author) will be 10*99=990 records where you can optionally store read, ip, device, etc. - Palma_Schamberger commented on June 14th 19 at 19:18
,
And in your case the table with read reviews will be 11000 records.

Wrong, in the worst case (every user will read all comments) will be 10*100=1000 records, where you additionally store the time of reading,


what do you mean 10 * 100? Where you will get the other 100 messages? - Violet_Wiso commented on June 14th 19 at 19:21
what is still "the other 100 messages" ? - Palma_Schamberger commented on June 14th 19 at 19:24
,
There are 100 clients and 100 comments, all of them are read by all users. How many records are in the table with unread comments? 0.
that was the beginning of my argument.

In fact, it is the conventional 100 messages, it all all all messages that will be written by users of all time. It is because of them, this table will continue to grow. - Violet_Wiso commented on June 14th 19 at 19:27
I mean , it does not change the fact, it radically changes the essence of what the sample will be longer and longer. - nicklaus.Will commented on June 14th 19 at 19:33
, aceponate, in your case, probably better to store the "unread comments", and then when the time comes to process implementation. - Violet_Wiso commented on June 14th 19 at 19:36

Find more questions by tags MySQLPHPYii