-
Notifications
You must be signed in to change notification settings - Fork 218
Improve the performance of checking payment methods #7413
Improve the performance of checking payment methods #7413
Conversation
The release ZIP for this PR is accessible via:
|
Size Change: -55 B (0%) Total Size: 992 kB
ℹ️ View Unchanged
|
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 will take over this since @alexflorisca is AFK.
Script Dependencies ReportThere is no changed script dependency between this branch and trunk. This comment was automatically generated by the |
959cbc6
to
cefcd67
Compare
This branch has some conflicts |
@alexflorisca does this close #7031? If so, let's add this info in the description |
It's already in the description. I'll catch up with @opr about this today and wrap it up |
cefcd67
to
45a1f25
Compare
/** | ||
* Internal dependencies | ||
*/ | ||
import { STORE_KEY as PAYMENT_STORE_KEY } from '../payment/constants'; |
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.
Need to import from constants here to avoid circular dependency
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.
Thanks Alex, working well for me! Code changes look fine.
Cool, E2E tests seem unrelated so merging |
* Improve the performance of checking payment methods * Use the default names of imports from @wordpress/data * Fix circular dependency * Fix __internalUpdateAvailablePaymentMethods Co-authored-by: Thomas Roberts <[email protected]>
This PR aims to improve performance of the C & C blocks by reducing the number of times we check that each payment method can pay. After the data store migration, we call
checkPaymentMethodsCanPay
for each change to the cart store. This is a function that does a lot of heavy processing (calls thecanPay
method for each payment method registered on the store). It was being run 4 times for standard payment methods, and 4 for express payment methods just on loading the cart page.I've done 2 things here:
__internalInitializePaymentStore
function to__internalUpdateAvailablePaymentMethods
to better reflect what it's doing. It now checks if the payment methods have been initialised and only calls the action to initialize them if they haven't. This allows us to call this function from a.subscribe()
function without worrying that the__internalSetPaymentMethodsInitialized
and__internalSetExpressPaymentMethodsInitialized
will be called multiple times.Fixes #7031
Testing
Automated Tests
User Facing Testing
WooCommerce Visibility
Performance Impact
This should speed things up slightly on the front-end