spree/spree — pull request #5676 by huoxito (2014-11-25 05:55:08+00:00)
Title: Using more objects in memory during checkout

I've been trying to address some points we always consider when thinking of how to resolve / improve spree performance. Working with objects in memory, doing less `object.reload` and saying good bye to famous `order.update!`.

I started by trying to reduce db queries / ar object loads when adding items to cart (`order.contents.add`), could go as far as running about half less db queries, see https://gist.github.com/huoxito/3d8bcf0d8fa24f54f429, and I've been trying to somehow benchmark this but I'm not really sure how to do it best yet.

These are some from a simple `Benchmark.measure` script https://gist.github.com/huoxito/2e0bc0b97420eb032329. The difference is not much at all really from a simple default spree install (with sample data only). But I'm curious to see how this would go with some more real world store scenario.

Also started looking at the transition from address => delivery and made some changes on the Stock::Estimator to reduce the number of hits on db as well.

I couldn't make all specs pass yet mostly because I'd need more time to catch where is it exactly we're missing fresh data and using the out of date objects from the database (there are some NOTEs on the code though that should help narrow down the hot spots).

Overall I feel like the end result here is going to be more code and possibly more complex code but I can't really see how else we can achieve better performance. Personally every time I've done something like `order.reload` is because I had lost track of the method calls and just reloading the object, or everything inside spree, would be the easiest way to go.

will still try to make those specs green but I wanted to share this with everyone to get feedback since I've spent already quite a decent amount of time on it.

// @BDQ @JDutil