Refactor Order::Updater#update so we don't call update_totals twice

Calling this method twice on every update is really expensive and not necessary.
This commit is contained in:
Matt-Yorkley
2021-04-26 11:14:27 +01:00
parent 9b52c453db
commit f52d03fbf4
2 changed files with 3 additions and 5 deletions

View File

@@ -19,6 +19,7 @@ module OrderManagement
# 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_all_adjustments
update_totals
if order.completed?
@@ -27,9 +28,6 @@ module OrderManagement
update_shipment_state
end
update_all_adjustments
# update totals a second time in case updated adjustments have an effect on the total
update_totals
persist_totals
end

View File

@@ -132,8 +132,8 @@ module OrderManagement
end
end
it "updates totals twice" do
expect(updater).to receive(:update_totals).twice
it "updates totals once" do
expect(updater).to receive(:update_totals).once
updater.update
end