For example, let's take the format of a forum, where we have multiple users and multiple threads. Say this forum wants to track which users have read which threads and, say, use that information to mark which threads are unread when viewing the thread list.
The only solution I can imagine is something that drops a record into the database each time a user visits a thread. I suppose there could be a 'mark all as read' button, which could employ a time stamp to help lessen the sprawl in the database... regardless this isn't a solution that impresses me.
I have a feeling that I'm missing something here... maybe Thanksgiving morning isn't the time to think over one's programming problems.
Is there a better solution out there for this? Any ideas?
- Drop a record in the database for each user-thread combination
- Or store this information in a file - one file per user. It may need to be locked/unlocked in case multiple logins by the same user are allowed.
Using a database record sounds like the most promising to me. It will generate a table with millions of rows very quickly if you have an active forum but it would be the simplest solution to implement. It will give a lot of flexibility for querying which users are reading what too.
I think I saw somewhere, maybe phpbb forum? anyway
there was a table in it with userid, threadid, last-read-datetime (let name it userAsRead)
then it would compare the last post made in that threadid vs last-read-datetime
for the mark as all read, it was a field in the usertable using the same logic as above
don't forget to clear the userAsRead if "mark as all read" is used, would save DB space
来源:https://stackoverflow.com/questions/323758/whats-the-most-efficient-way-to-remember-read-unread-status-across-multiple-ite