4

Asp.net mvc3 forum implementation. Part of the implementation is a feature that shows what posts have been read an what posts have not.

The way I have implemented it now is that I create an entry in my data for each user at creation of a new post, and then remove them as they are displayed to my users,I also delete all under entries older then 1 month.

I currently have 450 users, so it takes quit a long time to create them all.

I was thinking there must be a better way as large vbullitin or phpbb forums with more then 1000 users can do this without spending 2+ sek at post creation, to create all these entries, but I have not found it. I can see there some other questions about this on this site, but I have not found an answer I can use.

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
Androme
  • 2,399
  • 4
  • 43
  • 82

3 Answers3

2

You need to record user's last activity but storing everything in the database will not be efficient. Due to that, you'll also need to set cookies to know what threads they viewed. A bit of a hybrid approach but there are some lengthily discussions about it here:

Community
  • 1
  • 1
Teoman Soygul
  • 25,584
  • 6
  • 69
  • 80
0

One way to store less data and make things run faster: For each thread that a user reads, create a database entry to log the timestamp when they last viewed that thread. This way each user doesn't get an entry for every post - just per-thread... and only for threads they actually read.

You can easily then determine what within a thread is unread... if you have no timestamp in the DB for this user/thread, then it's all unread for them. If you have a timestamp, all posts in the thread after that timestamp are unread.

Robert Levy
  • 28,747
  • 6
  • 62
  • 94
  • Doing this will result in fewer reads but not inserts, as i will have to insert a row for each user, as doing checks if they already exists will be more time consuming. – Androme May 01 '11 at 15:26
  • Disagree that it will be more time consuming. It's not like you have to iterate over the entire table to realize that there isn't an entry for a specific user-thread combination. Databases are smarter than that (especially if you index the userid and threadid columns) and can search way faster than O(N) – Robert Levy May 01 '11 at 15:40
-1

Maybe each user should hold on to the IDs of the posts they have viewed rather than those that they have not viewed? It's going to be considerably less costly at the point of creation.

spender
  • 117,338
  • 33
  • 229
  • 351