Hi, Anyone got some slick ideas on how to sweep an AR session store? I have a few ideas how I can do it, just want to see if there is an elegant solution that someone is already using. Bob Silva http://www.railtie.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060228/7f9d25ca/attachment.html
More elegant than the rake task? rake purge_sessions_table # Drop and recreate the session table (much faster than ''DELETE * FROM sessions'') -Steve http://www.stevelongdo.com On 2/28/06, Bob Silva <me@bobsilva.com> wrote:> > Hi, > > > > Anyone got some slick ideas on how to sweep an AR session store? I have a > few ideas how I can do it, just want to see if there is an elegant solution > that someone is already using. > > > > Bob Silva > > http://www.railtie.net/ > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060228/f366608d/attachment.html
Steve Longdo wrote:> More elegant than the rake task? > > rake purge_sessions_table # Drop and recreate the session table > (much > faster than ''DELETE * FROM sessions'') > > -Steve > http://www.stevelongdo.comThat''s not a particularly nice way to do it for users that would prefer to keep their session data for a little while. Isn''t it better to do a nightly sweep of sessions that are, say, 3 weeks old? I keep login information (cookie) for up to 2 weeks, so I''ll probably just delete sessions after 16 days. But I''ll do it nightly to avoid a huge build-up. I have an SQL script that runs nightly to perform backups. I will probably just put the delete command in there unless there is some compelling reason to have Ruby do it. Jake -- Posted via http://www.ruby-forum.com/.
Here''s my trick. Actually make a session model in your app and leave it almost completly empty. Add a simple method to the session model called sweep or whatever. def self.sweep self.destroy_all(:coditions => ["updated_at < ?", 30.minutes.ago] end Now, in order to run this (either through cron, windows scheduler, whatever) your command, from the rails app directory: ruby script/runner "Session.sweep" And there ya go, that should do it for ya. Of course you can change the run time or session length to whatever you want. It has worked great for me. On 2/28/06, Jake Janovetz <jake@janovetz.com> wrote:> > Steve Longdo wrote: > > More elegant than the rake task? > > > > rake purge_sessions_table # Drop and recreate the session table > > (much > > faster than ''DELETE * FROM sessions'') > > > > -Steve > > http://www.stevelongdo.com > > That''s not a particularly nice way to do it for users that would prefer > to keep their session data for a little while. > > Isn''t it better to do a nightly sweep of sessions that are, say, 3 weeks > old? > > I keep login information (cookie) for up to 2 weeks, so I''ll probably > just delete sessions after 16 days. But I''ll do it nightly to avoid a > huge build-up. I have an SQL script that runs nightly to perform > backups. I will probably just put the delete command in there unless > there is some compelling reason to have Ruby do it. > > Jake > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060228/f38deed2/attachment.html
Cron is the way to go...I have a cron job that runs hourly on each of my rails sites. It does different things based on the site, but one of those things is deleting sessions older than a few hours. Maybe look into RailsCron as well. I just launch mine from good ol'' cron. -- seth at subimage interactive http://www.subimage.com/sublog/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060228/e2f869d8/attachment.html
The great things about RailsCron is that if you ever need to move your application, your cron job will move with you as well... -- -- Tom Mornini On Feb 28, 2006, at 11:53 AM, subimage interactive wrote:> Cron is the way to go...I have a cron job that runs hourly on each > of my rails sites. > > It does different things based on the site, but one of those things > is deleting sessions older than a few hours. > > Maybe look into RailsCron as well. I just launch mine from good ol'' > cron. > > -- > seth at subimage interactive > http://www.subimage.com/sublog/ > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060228/4afd0316/attachment-0001.html