Skip to content

Commit

Permalink
Wrap OrderUpdater#update in a transaction
Browse files Browse the repository at this point in the history
As of solidusio#1479 we are doing more work inside of OrderUpdater. We're
doing additions and deletions of tax adjustments, which also causes more
touching of records.

This is all made faster by wrapping the entire update in a transaction.
All the writes can be queued together by the DB, and as of rails 5,
dependent touching is grouped together to the end of the transaction.
  • Loading branch information
John Hawthorn committed Oct 31, 2016
1 parent 4dd6680 commit 4d34642
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions core/app/models/spree/order_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ def initialize(order)
# object with callbacks (otherwise you will end up in an infinite recursion as the
# associations try to save and then in turn try to call +update!+ again.)
def update
update_item_count
update_totals
if order.completed?
update_payment_state
update_shipments
update_shipment_state
@order.transaction do
update_item_count
update_totals
if order.completed?
update_payment_state
update_shipments
update_shipment_state
end
run_hooks
persist_totals
end
run_hooks
persist_totals
end

def run_hooks
Expand Down

0 comments on commit 4d34642

Please sign in to comment.