-
-
Notifications
You must be signed in to change notification settings - Fork 730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Adjustments] Reduce adjustments callbacks #7036
[Adjustments] Reduce adjustments callbacks #7036
Conversation
e0d9b0a
to
09f731d
Compare
@@ -20,6 +20,8 @@ def recreate_all_fees! | |||
create_line_item_fees! | |||
create_order_fees! | |||
end | |||
|
|||
order.update! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling order.update!
here (in #recreate_all_fees!
) is useful, it means we can stop manually calling order.update!
in various places where we call order.recreate_all_fees!
, which simplifies things.
@@ -95,6 +95,7 @@ def process_return | |||
credit.save | |||
|
|||
order.return if inventory_units.all?(&:returned?) | |||
order.update! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return authorizations add an adjustment on the order (which was updating the order totals automatically via the callback). It needs to be called once after a return is processed, so we can just do it explicitly.
def self.without_callbacks | ||
skip_callback :save, :after, :update_adjustable | ||
skip_callback :destroy, :after, :update_adjustable | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥 😄
# during cart population, for both taxation and enterprise fees. This operation triggers a | ||
# costly Spree::Order#update!, which only needs to be run once. We avoid this by disabling | ||
# callbacks on Spree::Adjustment and then manually invoke Spree::Order#update! on success. | ||
Spree::Adjustment.without_callbacks do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥 😄
7a1db62
to
1b97e65
Compare
Not sure how indicative this is, but the build just finished in ~16 minutes total, and other builds seem to be taking ~24 minutes total... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty reasonable, and like it will definitely help with performance. It is a little surprising that we didn't end up with more failing tests that needed to be changed. I feel like the test coverage around order totals is pretty robust though, right? So the green build should give us a good degree of confidence here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥 😄
I'm wondering if we need some more specific testing notes. The risk is that we are forgetting about cases that need to update the order.
Lets see... cart and checkout, then admin order edit (line items and adjustments sections), customer order edit (if the hub allows editing open orders), Bulk Order Management, any other places? I guess subs as well.
If we stage this PR it'll include #6858, so it should be fine. But yeah if we merge #6858 I'll update this PR to point at master. |
Ok, great - so let's stage this PR, and include the test cases from #6858 as well as those you just pointed out Matt, thanks 👍 |
🎉 Hooray for this one team :-D |
Hey @Matt-Yorkley , I'm splitting the testing in two comments, to reflect the separate PRs. So this first go at this concerns the changes introduced by #6858. Test cases on shipping fees I think this PR does not really touch much zones/shipping categories, at least directly. Anyway, I thought it's probably a good idea to have a quick test to make sure that:
3.a) While editing orders (for SM with per order calculators) 3.b) While editing orders (for SM with per item/amount calculators)
This is looking pretty good - that's awesome 🎉 (To be continued, on what concerns #7036) |
With #6858 it's mostly just that the shipping cost should be recorded correctly and show up on the order and in the totals as usual. I think it's pretty well covered by specs as well 👍 |
Ok, thanks @Matt-Yorkley 👍 Continuing with testing this PR... Observed no significant difference in the deployment time, in staging-UK: Checked updating order totals with taxes and fees as: as Customer, at
as admin, while
Comparison between backoffice and frontoffice. The mismatch after clicking "Update and Recalculate Fees" relates to the shipment fee, which needs to be updated manually - I think this the expected behavior: I found this it was possible to update shipment fees, manually - is this the expected behavior @Matt-Yorkley? I'm not so clear on the "Associated Adjustment Closed" - is there some inception or documentation on this? (adding the feedback label) So I think we are good here. Moving to ready to go. PS: It seems we do observe bug #5368 (shipping fee with inclusive tax) I've scratched this from the previous comment. Although the extra tax value does not end up on the order total. |
So when changing an order's contents in admin, you have to explicitly update the shipping fee if you want it to be recalculated? Sounds pretty reasonable to me. There haven't been any specific changes made to that part of the form. It works and all the totals are correct, right? |
Yes, totals match 👍 I'm wondering if the fact that it needs to be done explicitly does not contribute to the shipment of orders with incorrect shipping fees, after editing line items, but agree: this does not related to this PR. |
The removed test here was checking for adjustments that have an amount of zero and are eligible. If the amount is zero, it will already be marked as ineligible.
1b97e65
to
29c5703
Compare
What? Why?
Removes the
after_save
callbacks inSpree::Adjustment
that trigger expensive calls toorder.update!
, which in turn can trigger a number of other transactions and callbacks.Some quick testing shows this cuts the number of transactions during checkout processing in half. Using production data and submitting a fairly simple order with 3 line items triggers over 1100 SQL hits, and
order.update!
appears 700 times in the backtraces for those queries/transactions. After this, the total SQL count is down to ~500. This should have a similar effect in various other parts of the app where adjustments are touched, like updating orders via admin (which is also a big pain point currently).🎉
Note: target branch needs to be updated after #6858 is merged.
What should we test?
Order totals should be correct when editing an order or it's adjustments.
Release notes
Removed adjustment callbacks that call order.update!
Changelog Category: Technical changes