Using sessions to give count of current visitors

I would like to list the current number of visitors on my site. To do
this I’m counting the number of sessions that have been updated in the
last five minutes. Here’s what I’m doing to make it work, please let me
know if there’s a better way:

First I’ve created a Session model so that I can say Session.find

class Session < ActiveRecord::Base
end

Next in my controller I’m searching for all sessions that have been
updated in the last 5 minutes like this:

def dashboard
@active_users = Session.find(:all, :conditions => [“updated_at > ?”,
Time.now - 5.minutes]).size
end

This all seems to work fine, I’m just wondering if it’s somehow a bad
idea to create the Session model, maybe it make’s active record work
harder since it may now need to associate a model with each session it’s
working with?

Thanks for any recommendations.

Jesse

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs