Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write "Last Seen" logic like that on Stack Overflow

I'm working on an application that has similar logic as SO with regards to when the user was last seen. I've run into a conceptual problem that I'm hoping some of you Guru's can help me out with.

All activity is logged in an ActivityLog table in the database

When a logged in user hits the site and a new session is created, I update the activity log with the UserID and some very generic info. Same thing happens when they create a new record, update their profile, etc.

The problem I'm having is this.

If I use the most recent activity item, then navigate to my personal account page, the "Last Seen" shows up as 1 second ago because I JUST hit the db on session start... This is not good because I want to see what I was "last" there, not when I'm there "now".

However, if I use Skip(1).Take(1) to get the second record in the database, then when someone else views my profile while I may have "just" signed on... they'll see that I was on say a week ago and not today.

What kind of logic would you use in order to have your cake and eat it too?

I'm using ASP.NET MVC2 and Linq to SQL, but I think this question is more language agnostic.

like image 887
Chase Florell Avatar asked Jul 06 '10 17:07

Chase Florell


People also ask

How do you implement the last seen feature?

0.70, introduces a unique 'My Contacts Except' choice to the 'Last Seen' section of the app's privacy controls. To utilize the function, go to settings > privacy > Last seen > My Contact list, and enter the names you want to add from whom you want to hide your 'last seen' status."

What is this stack overflow?

What is stack overflow? A stack overflow is a type of buffer overflow error that occurs when a computer program tries to use more memory space in the call stack than has been allocated to that stack.


3 Answers

It sounds like you could just show the second most recent record for the current user, and for all other users show the most recent one.

like image 63
Brian MacKay Avatar answered Oct 26 '22 05:10

Brian MacKay


What I would do (simply to avoid a large logic loop) would be to add two fields. current_seen and last_seen. On login move current_seen to last_seen and set current_seen to the current timestampe. Then display last_seen as their "Last seen on XX/XX/XXX".

like image 43
Josh K Avatar answered Oct 26 '22 03:10

Josh K


One place to look is at the source code to OSQA (the open source q&a system) -

http://www.osqa.net/

And yes, it looks a lot like StackOverflow (to say the least).

like image 21
Kris Krause Avatar answered Oct 26 '22 04:10

Kris Krause