Skip to content
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

Avoid re-creating tax adjustments #1570

Merged

Conversation

jhawthorn
Copy link
Contributor

@jhawthorn jhawthorn commented Nov 1, 2016

Previously, ItemAdjuster#adjust! would always destroy all tax adjustments on the item and recreate them. This was unnecessarily slow in the common case of needing no changes (especially following #1479).

This changes ItemAdjuster#adjust! to instead update the adjustment for a rate if it already exists, create adjustments if they are missing for a matching rate, and destroy adjustments for rates which are no longer matching.

With this change, the speed of an order.update! which requires no changes is comparable to before #1479 🎉

Comparison of queries run

@jhawthorn
Copy link
Contributor Author

jhawthorn commented Nov 1, 2016

One potential issue I've spotted is that this has changed the behaviour of an existing tax rate which had an amount and then later became0 (but otherwise still matched). Previously, it would have been removed after becoming 0. This code, in it's current state, will leave the adjustment, but update the amount to be 0. I'd like to change this so that it is consistent (it shouldn't have a "memory" of it's past tax rates).

Another (preexisting) issue is when order_tax_zone(order) has a zone but later becomes nil. adjust! will exit early, but it should probably remove all tax rates in that case. Addressed in #1575

@jhawthorn jhawthorn added this to the 2.1.0 milestone Nov 3, 2016
This is done in the interest of having as few special cases as possible.
Nothing in our test swite exposed this functionality, and it's probably
not a case worth optimizing for.
Previously, ItemAdjuster#adjust! would always destroy all tax
adjustments on the item and recreate them. This was unnecessarily slow
in the common case of needing no changes (especially following solidusio#1479).

This changes ItemAdjuster#adjust! to instead update the adjustment for
a rate if it already exists, create adjustments if they are missing for
a matching rate, and destroy adjustments for rates which are no longer
matching.
@jhawthorn jhawthorn force-pushed the avoid_recreating_tax_adjustments branch from cbc7062 to c661c04 Compare November 7, 2016 17:55
@peterberkenbosch
Copy link
Contributor

I actually like the 0 amount better then no adjustment at all, there is a difference accounting-wise between 0 amount tax and no tax.

@peterberkenbosch
Copy link
Contributor

👍

Copy link
Contributor

@mamhoff mamhoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Nice work @jhawthorn !

Copy link
Contributor

@cbrunsdon cbrunsdon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The zero dollar adjustments might start showing up on peoples front ends when they display adjustments to people... but I can't think under what circumstance that would happen so I'm okay with the change.

@jhawthorn jhawthorn merged commit 6e7b6f8 into solidusio:master Nov 28, 2016
@jhawthorn jhawthorn deleted the avoid_recreating_tax_adjustments branch November 28, 2016 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants