I question the separation of concerns there. A cron is really the right way to do it because it's a periodical operation. If the site ever becomes more popular or the code is reused, you'll be the guy that wrote code to do table scans for removing old sessions when new ones are created rather than a simple cron job.
If you environment is too restrictive to allow a nightly cron, you could try delayed jobs and as a last resort, make a rake task that you can run to clean them up manually. Having old carts isn't the concern of an action made to create new carts. Martin Emde Tw: @martinemde On Wed, Nov 25, 2009 at 12:45 PM, Scott Olmsted <[email protected]> wrote: > > I have a new client for whom I'm adding a feature to their shopping cart. I > don't think their previous developer quite finished the site; there was an > obvious bug that generated an error when one tried to remove something from > the cart. > > But the surprise was that the database contains 644,000 sessions! That's > 150MB. Also 18,000 shopping carts, all generated in a little over a year, > that's maybe 1600 sessions and 50 carts a day, pretty low volume (they sell > expensive stuff). It would be advisable to set up a cron job to remove old > sessions and carts, yes? But I had another idea. > > On another low volume site I created, some pages displayed tables that > could also be downloaded as csv's. The csv's are generated at the same time > as the displayed table, it was just easier that way. After generation > they're saved to the database, available for download. Rather than add a > cron job to remove old csv's, when a table and new csv are generated, the > controller searches for csv's older than a couple days and deletes them. > > Any problem with doing the same thing on the site with the shopping cart? I > don't think I would add the check to every new session. Maybe when creating > a new cart it could remove old sessions and carts; if that caused a small > delay it would be tolerable, the user is more likely to be patient when > waiting for the cart to first come up. Comments? > > Thanks, > > Scott > > -- > SD Ruby mailing list > [email protected] > http://groups.google.com/group/sdruby -- SD Ruby mailing list [email protected] http://groups.google.com/group/sdruby
