biddyweb / substruct

Automatically exported from code.google.com/p/substruct
0 stars 0 forks source link

DB littered with CART items #135

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Hit /store a bunch of times.
2. See a ton of empty CART orders in the db

What is the expected output? What do you see instead?
With large volume sites, this probably isn't the best behavior.

Perhaps provide a rake maint script to cleanup these empty carts - or figure 
out a way not to store 
them in the DB at all. Either solution must respect the issues raised with 
issue 114

Original issue reported on code.google.com by subim...@gmail.com on 20 Sep 2008 at 12:54

GoogleCodeExporter commented 9 years ago
I'd suggest just having a cart instance but never actually saving it until an 
item 
is added to it, either that or never creating and assigning a cart instance 
until an 
item is added to it [make that before_filter :only => :checkout] or something.
-=r

Original comment by rogerdp...@gmail.com on 10 Mar 2009 at 2:04

GoogleCodeExporter commented 9 years ago
That's how the old code used to work and it was causing massive issues when you 
tried
to checkout, then go shop for more items. Removing that method of working is 
what
fixed that nasty bug. Re-creating it is not something I'd like to get into.

This should be solved, but in another manner.

Original comment by subim...@gmail.com on 10 Mar 2009 at 11:02

GoogleCodeExporter commented 9 years ago
PS: The current method was chosen to fix bugs - issue 114, issue 111

Original comment by subim...@gmail.com on 10 Mar 2009 at 11:06

GoogleCodeExporter commented 9 years ago

  # MAINTENANCE ===============================================================

  desc %q\
  Hourly maintenance task that should be run on your Substruct site.
  Does some housekeeping so the DB is in order.
  Remember to pass it the proper RAILS_ENV if running from cron.
  \
  task :maintain => :environment do

    puts "Removing crusty sessions..."
    stale = Session.find(:all, :conditions => ["updated_at <= ?", Time.now -
Session::SESSION_TIMEOUT])
    stale.each { |s| s.destroy }

    puts "Removing carts older than 10 days"
    stale_carts = Order.find(:all, :conditions => ["order_status_code_id = ? and
DATE_SUB(curdate(), interval 10 day) > created_on"], 1)
    stale_carts.each { |c| c.destroy }

    puts "Removing empty carts older than 24 hours"
    stale_carts = Order.find(:all, :conditions => ["product_cost = 0 and
order_status_code_id = 1 and DATE_SUB(curdate(), interval 1 d\
ay) > created_on"])
    stale_carts.each { |c| c.destroy
  end

Original comment by flyfish...@gmail.com on 7 Oct 2009 at 5:19

GoogleCodeExporter commented 9 years ago
FYI, the above method is a bit slow for removing carts. This is a bit better.

# Clear out empty CART orders older than a day
Order.destroy_all(%Q\
  order_status_code_id = 1
  AND DATE(created_on) < CURRENT_DATE
  AND product_code = 0
\)

Original comment by subim...@gmail.com on 7 Dec 2009 at 1:45

GoogleCodeExporter commented 9 years ago
Fixed in r185

Original comment by subim...@gmail.com on 26 Dec 2009 at 5:58

GoogleCodeExporter commented 9 years ago
Fixed for real with r316

Original comment by subim...@gmail.com on 29 Aug 2010 at 12:17