-
Notifications
You must be signed in to change notification settings - Fork 10.8k
get_product_variation_image_ids: fetch image ids directly from meta #60210
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
base: trunk
Are you sure you want to change the base?
get_product_variation_image_ids: fetch image ids directly from meta #60210
Conversation
📝 WalkthroughWalkthroughA performance optimization was implemented in the WooCommerce plugin's Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: .coderabbit.yml 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (21)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
Test using WordPress PlaygroundThe changes in this pull request can be previewed and tested using a WordPress Playground instance. Test this pull request with WordPress Playground. Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit. |
This reverts commit 0cd27dc.
94cb3b7
to
8f6871a
Compare
Changes proposed in this Pull Request:
Refactor
get_product_variation_image_ids()
to directly query image IDs viaget_post_meta
instead of instantiating fullWC_Product_Variation
objects.I was inspired after profiling showing this function being called multiple times per page (

/product-category/clothing-grocery-garden/
) and seeing a long loop/tail of function calls each time:If we look at the bottom up view of this function, we can see a lot of time is spent in the chain of creating objects and data stores filling out information that isn't the image id:

Ultimately, the function is fetching one bit of meta:
And the data class it inherits from calls a filter when we
->get_prop( 'image_id'
There are two complexities:
woocommerce_product_variation_get_image_id
filter on the ids$this
) as the second parameterTherefore, we can apply this optimization, but only if there's nothing on the filter. Note that since we're in a class that's designed as a helper for the product gallery block, we're always in "view" context.
How to test the changes in this Pull Request:
Goal 1: Seeing a gallery of variable products
wc-smooth-generator
(https://github.com/woocommerce/wc-smooth-generator)wp wc generate products 50 --type=variable
wp wc generate attributes 36 --terms=200
andwp wc generate products 50 --type=variable --num-attributes=7 --max-terms=20 --max-variations=35 --use-existing-terms
/product-category/clothing-grocery-garden/
Goal 2: Observing the current results and timing on trunk
Use something like:
See some times over 10ms like:
Goal 2: Observing the propsed results and timing on this branch
Like above. Add:
To the top of the function and
to the bottom. You should see the same results, but faster.
For me, for example:
Testing that has already taken place: