I am looking for a optimal way to store info about which users already read what posts on simple forum engine I am building, so I can mark new posts for them. I am looking for both space- and performance- optimized way.
The first that comes to mind is the pure way of creating table with post_id and user_id columns in which each row would represent read post by a user. But this leads to a lot of data inserted and performance stress on the database. And even more of data inserted after clicking on "mark all as read". If all users would have read all posts, this would mean (users count) * (posts count) rows in the database.
This method could be optimized to store timestamp for each thread and each user and update these timestamps each time user reads new posts. But it's still a lot of data.This would mean (users count) * (thread count) rows.
I can simplify this to storing "last visited" timestamp on the forum (i.e. thread category) level. This would mean (users count) * (forum count), which is not that bad, but there is a question when should I update this timestamp, so it's not too much confusing for users.
Thanks for any ideas.