You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Currently all shipping method checkers are being called on every modification to the Order.
This is far from optimal resources utilization and makes async checks especially with external services slow and expensive.
Describe the solution you'd like
only re-run the checkers if a ShippingMethod is already assigned to the order.
if so, only re-check the single assigned checker.
introduce new config property "deferred" that would defer a check (not run check on every Order change) to "checkpoints" (eligibleShippingMethods call, OrderStateTransition from "AddingItems" - maybe checkpoints could be configured as new Event, so the custom "checkpoints" could be added by publish() and check would run on every Event emission.
This deferred option would be viable option for more resource expensive checks - e.g. calls to external services, DB queries etc.
Describe alternatives you've considered
Saving a state of the Order when last check was invoked and skip the heavy lifting if not needed.
Another solution to the problem of minimizing redundant checks:
We could have an approach kinda similar to React's shouldComponentUpdate method, i.e. allow the dev to provide a function which is used to determine whether or not to re-run the check.
The return type T gets cached and is compared to the last result (using an object-equivalence comparison). If it is unchanged, the check skipped.
For example, imagine a checker which depends country and postcode of the order:
constchecker=newShippingEligibilityChecker({code: 'checker',description: [],args: {},check: (ctx,order)=>{// some super expensive async check...},shouldRunCheck: (ctx,order)=>{returnorder.shippingAddress;},});
With the above checker, each time the order contents are changed, before running the check function, Vendure would first run the shouldRunCheck function and compare the shippingAddress object with the cached object from the last check. If they are equal, the check function will be skipped.
Relates to #536. This commit implements the following changes:
1. The `check` function is only run on changes to the order _if_ a ShippingMethod has been assigned
to the Order.
2. If the order has a ShippingMethod, then _only_ that method's `check` function is invoked on
changes.
Is your feature request related to a problem? Please describe.
Currently all shipping method checkers are being called on every modification to the Order.
This is far from optimal resources utilization and makes async checks especially with external services slow and expensive.
Describe the solution you'd like
This deferred option would be viable option for more resource expensive checks - e.g. calls to external services, DB queries etc.
Describe alternatives you've considered
Saving a state of the Order when last check was invoked and skip the heavy lifting if not needed.
Slack thread: https://vendure-ecommerce.slack.com/archives/CKYMF0SU8/p1604053389143600
The text was updated successfully, but these errors were encountered: