mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-06 22:36:07 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user