Best unofficial Apache Server developers community
Username
Forgot password?
Sign in with Twitter account
Sign in with Facebook account

MySql : how can I implement a sort of "read/not read yet" topics?

1

163 views

Hi. I'm about to implement a list of topic/argument in my forum, and I'd like to insert a sort of flag like "read/not read yet" for each message, regard each user in my website.

I think at somethings like this : a table watched_topics with id(INT), user(VARCHAR) and topic_id(INT). When a user watch the page, I'll insert (if the data doesn't exist) these information.

When another user will insert a new message in a topic, I'll delete from the table watched_topics all line with that topic_id.

That could provide a trouble : Think about to 9000 topics and 9000 users that have watched all topics : the table will be so big (9000x9000=81000000).

So, I think is not the best strategy to implement this kind of stuff! Any suggestion would be appreciated :)

Cheers

asked January 28, 2011 4:50 am CST
posted via StackOverflow

3 Answers

2
 

Your suggestion sounds good. I would make user-field also a foreign key - it gives you a bit more flexibility.

Are you sure all 9000 topics are read by all 9000 users? I mean is this reality? Like you said, topic-entries are deleted when new message is added. And when that happens, another 9000 entries are deleted :)

I would index the table and go with your suggestion (with user_id change). If the table size gets in your way, you can always change the implementation later. Most likely it will never be the issue anyway.

answered January 28, 2011 5:23 am CST
2
 

May I suggest a different approach?

Make use of web browser history mechanism.

Every topic can get a new, unique URL every time a new message is added there. It could include the number of messages, last modified time or a combination of both.

If the user did see the topic, he must have visited it, so a properly set up CSS can help identifying the read ones. You can even use some client-side scripts to modify the behaviour of the page based on that.


Another way to do that would be to keep the watched topics table the way you want to do it, but also store last visit time in user's profile and show all topics as read that haven't changed since that time.


However it's pretty safe to assume that all users reading all topics is very unlikely.

answered January 28, 2011 5:23 am CST
0
 

For the deletion: you could save what the latest msg-ID was the user saw. This way you do not have to perform a lot of delete actions every time a msg is posted in a much-viewed topic.

answered January 28, 2011 5:23 am CST

Your answer

Join with account you already have


Sign in with Twitter account
Sign in with Facebook account
Sign in with Google Friend Connect

Preview
Similar questions