-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Clear post cache after updating menu order for products. #34195
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
Conversation
Some notes on performance... ✍🏽 Switching from Similarly, to keep things snappy, I opted only to call |
Test Results SummaryCommit SHA: c5001f2
To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
Using direct SQL and bypassing core APIs is always going to cause problems. You mentioned it's done for performance reasons, but did you compare the performance of the two after adding |
Thanks for the question, @bazza.
I should start by acknowledging that, by itself, this is a very naive approach (because, if we literally just replace the existing So, a better strategy would be to check if the menu order even needs to be modified before updating (ie, perform a check along the lines of
Just from local testing (with a catalog of 500 products, and where re-ordering triggers an update to 4 rows, and where I perform 5 runs per test-case to get an average):
Yes, it was a wash. From there:
|
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 good to me.
While I agree that ideally we would have access to some WP functions to performantly update the menu order in bulk, the approach here not only fixes the issue but does so with minimal impact, as opposed to changing the code to use wp_update_post()
.
Maybe we can add an issue to review some of these places where we've deviated from the "official" way of doing something for performance (or other) reasons and either re-work the code then or propose new APIs to upstream.
Note: I don't currently see any good reason not to merge this as-is, but will hold off on doing so for a few days, just in case we want to discuss further.
@bazza let me know if any other questions/concerns on this one. |
Agreed -- can we please create an issue to review anywhere we're doing this sort of query, so that we can propose improvements to WordPress Core that would enable us to use official APIs vs direct queries? |
Hi @barryhughes, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:
|
* trunk: (97 commits) [COT] Respect status flags `show_in_admin_(all|status)_list` in orders list table (#34290) Fix a bug crashing wp-env 5.1.0 in CI (#34274) Add unit tests for orders milestone note (#34295) Update "context" prop of task list click/view event (#34297) Update the cherry-pick workflow to not run for non-existent branches (#34325) Update CI to use wp-env for api, e2e and performance tests (#34311) Clear post cache after updating menu order for products. (#34195) Add `wc com disconnect` command (#33999) Fix review shipping option task title (#34294) Add Facebook Extension to Onboarding (#34303) Add Media Uploader component (#34181) Add SortableList component (#34237) Change to use fetch depth 0 (#34288) Add SplitDropdown component (#34180) Fix/forgotten template version (#34308) Fix/34271 unlimited results (#34289) Add product name and checkboxes for Product details (#34214) Prepare Packages for Release (#34299) dev: move guided tours into consolidated folder (#34279) Add flag to state it is in dev mode so tools are installed like phpun… (#34258) ... Conflicts: plugins/woocommerce/includes/admin/helper/class-wc-helper.php plugins/woocommerce/includes/cli/class-wc-cli-com-command.php
When Advanced Post Caching is in effect, changes made to product menu order appear not to take effect because the cached results (for the posts query) are not invalidated.
Closes #31389.
How to test the changes in this Pull Request:
Please also refer to the linked issue which contains a good screencast and some solid testing instructions.
Demo
Here's how things work without the fix (note how after reordering the products I click on Sorting to refresh the page, and the order reverts to how it was at the start of the video):
withoutfix.mov
And here is how things work with the fix. This time, on refreshing, the new order persists:
withfix.mov
FOR PR REVIEWER ONLY: