Forum: Ruby on Rails Online users and sessions - logic help

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
60071e44382435f0f42bf6c3f6e29889?d=identicon&s=25 Scott Holland (ginsberg1982)
on 2007-02-23 17:41
Hello Guys,

I have an application which lets users login . In order to see how many
users are online (active in the last 20 mins) I have a before_filter on
every page which updates a column in the user table called
“last_hit_server”

This is a little silly and is really slowing things down.

Here are my aims:

•  I need to create a list of all the users active in the last 20 mins
•  I need to be able to see when a user was ‘online’


Obviously I need to start tracking sessions, but I really need some help
with the logic of it

Here is what I’m thinking so far…

----------------------------------------------------------------------------

* When they log in I first check to see if there is a session already
assigned to that user
  * (If there is – I destroy it)
* I then create a new session and assign the user id to it.


“Who’s online”: I can then pull out a list of all the sessions which
have been updated in the past 20 mins along with the user id

When they log out, I destroy the session

----------------------------------------------------------------------------


But this doesn’t solve my problem of seeing when a person was last
‘online’ if I have destroyed the session

Any suggestions?
2017657725dd1bce83dc8a1e2e991d04?d=identicon&s=25 Luke Ivers (Guest)
on 2007-02-23 19:45
(Received via mailing list)
You've already said that you destroy sessions when they log in if the
session still exists... so just don't destroy the session when someone
logs
out.  You're left with an idle session that exists until the next time
they
log in this way, but you can always set up some kind of scheduled thing
(varies depending on OS) that will go in and clean up any sessions that
haven't had activity in <X> amount of time.
This topic is locked and can not be replied to.