gobigwin/spree — pull request #15 by BuckBuchanan (2014-11-30 17:25:16+00:00)
Title: Feature/non locking atomic update on inventory update

We still had a few problems caused by the pessimistic lock because of deadlocks. The reality is, in this place in the order checkout process, where the payment has been received and we want to fulfill the order, we do not care about locking on the variant table. All we care about is adjusting the inventory accurately and immediately without putting the order at risk of having its after_complete callback fail. So I'm just going to disable optimistic locking and do an atomic SQL query. The ActiveRecord update_counters method will result in a SQL statement that looks like this:

UPDATE "spree_variants" SET "count_on_hand" = COALESCE("count_on_hand", 0) - 1 WHERE "spree_variants"."id" = 12077