spree/spree — pull request #4636 by gmacdougall (2014-05-01 18:11:30+00:00)
Title: Optimize touch_taxons on product.

This will touch all of the taxons and taxon ancestors for a product
using a constant number of updates (2, one for taxons, one for
taxonomies).

Previously the number of updates would be 2 * the number of taxons &
taxon ancestors, as it would update the taxonmy for each taxon on each
update.

Example Case:

I encountered this issue when adding a new stock location to a store which has 890 products, and 265 taxons. With propagate all variants on, it needs to insert a new stock item for each variant.

Therefore it needs to:
* Insert a stock item
* Touch the variants timestamp
* Touch the products timestamp
* Touch the timestamp of the products taxons, and all ancestor taxons
* Touch the timestamp of the taxonomy for each of these taxons

Here is a comparison of creating a new stock location before and after on this sample data set:

Metric | Before | After
--------| ------- | -------
Log | [Gist](https://gist.github.com/gmacdougall/b8c789d5dadda74bb745) | [Gist](https://gist.github.com/gmacdougall/b51af2f6912ccdd8f53f)
Total Queries | 96,787 | 14,624
Total Updates | 50,358 | 3,560