spree/spree — pull request #5121 by brchristian (2014-08-04 01:50:42+00:00)
Title: Speed up rename_adjustment_fields migration

I went to perform this migration on our production db while our store was in maintenance mode and realized it was going to take many hours -- it was loading some million or so Order objects, one at a time.

The first change is that we go from loading all Adjustments and asking whether their adjustable is an Order to just scoping the Adjustment call to only ask for the ones that are. That saved us about one million `if` statements.

The second change is to simply copy the `adjustable_id` over to `order_id` without ever fetching the Order -- who needs it? This saved us about one million ActiveRecord queries.

Happy to pass the fruits along to others on the 2.1--2.2 upgrade path!