/solidus-garbage-cleaner

A little gem that helps you cleanup old, unneeded data from a Spree database.

Primary LanguageRubyBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

Solidus Garbage Cleaner

Build Status Code Climate

This extension cleans your Spree database from unneeded data. When your website grows, it could be useful to delete these old records to improve database performance.

Important notice: This extension can delete a lot of stuff from your database. It is thought to be used with some default Spree behaviors so be sure to know what you are doing, expecially if your app has a lot of custom stuff!

What does this garbage contain?

Incomplete orders

By default incomplete orders are kept even if they are not completed. This extension searches for incomplete orders and deletes them and their dependent association instances:

  • line items
  • payments
  • shipments
  • return authorizations
  • adjustments

Installation

Add the gem to your Gemfile:

gem 'solidus_garbage_cleaner', :git => 'git://github.com/ETBD/solidus-garbage-cleaner.git'

Run bundle:

bundle

Usage

To verify presence of garbage in your database run the stats rake task:

rake db:garbage:stats

To delete garbage from your database run the cleanup rake task:

rake db:garbage:cleanup

Configure the number of days after which records are considered garbage

For each model that collects garbage records you can choose after how many days those records are marked as garbage. Default value is 7 (one week). To change this default value you can run from the rails console:

Spree::GarbageCleaner::Config.set(:cleanup_days_interval, 10)

Configure the timestamp column to be used

By default, an item is flagged as garbage if the created_at date is older than the interval. This can be changed to use updated_at (or any other datetime field) by setting the config variable:

Spree::GarbageCleaner::Config.set(:timestamp_column, 'updated_at')

Setup a cronjob to cleanup garbage

You can setup a cronjob that periodically runs the cleanup rake task for you. Just add the whenever gem to your Gemfile and this to your config/schedule.rb:

every 1.day, :at => '5:00 am' do
  rake "-s db:garbage:cleanup"
end

Testing

Be sure to bundle your dependencies and then create a dummy test app for the specs to run against.

$ bundle
$ bundle exec rake test_app
$ bundle exec rspec spec

Copyright (c) 2012 NebuLab, released under the New BSD License