Page 1 of 1

New threads since last visit

Posted: Tue Jun 30, 2009 5:09 pm
by Cirdan
This is harder than first thought. So I have a variable for each user called "last_seen" that gets updated every 10 minutes to the database. This works for knowing when the user last visited the site, but is worthless when using it to check for which threads are new.

For example, the user visits the site's forum and notices that several of the boards have new posts. So he begins at the first board of his interest and spends 10 minutes reading the posts. After he finishes with the posts in this board he goes back to the index only to find none of the boards have been marked as having unread posts.

The "last_seen" variable becomes inaccurate for checking which threads are new. This could easily be fixed by capturing the "last_seen" variable once at the beginning then using that. However, the way my "remember me" feature works is by simply keeping the session data/cookie after the user's client has closed ( Zend_Session::rememberMe() ). Because of this, the captured "last_seen" variable becomes inaccurate again because it could have been set a few weeks ago.

I'm having a hard time trying to figure out how to fix this. I thought of having another timestamp which would be used to indicate when "last_seen" would be updated, but that won't work because you can't guess how long a person will be on a page of the site. If someone could give me some tips on how to solve this, that would be great.

Re: New threads since last visit

Posted: Tue Jun 30, 2009 5:26 pm
by Cirdan
I just got idea for a solution. When the user visits the site, I load all of the threads/boards that have been updated since the user's "last_seen" into a 2d array ([board_id][thread_id]). When a thread has been viewed, I pop it out of the array. After I load the array, I update the captured "last_seen" variable to what it is in the database. Then on every page load, I query the database for any new posts/threads then add them to the array.