-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Reuse block metadata in WP_Theme_JSON::get_valid_block_style_variations()
for better performance
#7586
Reuse block metadata in WP_Theme_JSON::get_valid_block_style_variations()
for better performance
#7586
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
@joemcgill @ramonjd Please review when you have moment. Thanks |
This change makes sense to me. Good idea to reduce the calls to I did a quick sweep for other instances of |
WP_Theme_JSON
WP_Theme_JSON::get_blocks_metadata()
calls
WP_Theme_JSON::get_blocks_metadata()
callsWP_Theme_JSON::get_valid_block_style_variations()
for better performance
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
protected static function get_valid_block_style_variations( $blocks_metadata = array() ) { | ||
$valid_variations = array(); | ||
foreach ( self::get_blocks_metadata() as $block_name => $block_meta ) { |
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.
Maybe we should still call self::get_blocks_metadata()
in case no value was provided, i.e. as default?
Since this method is protected
(not private
), in theory someone else could have overwritten this class. Highly unlikely but possible. Additionally though, not requiring the parameter makes using the method more ergonomic in situations where it hasn't been computed before.
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 already added $blocks_metadata = empty( $blocks_metadata ) ? static::get_blocks_metadata() : $blocks_metadata;
if the value is not passed of empty.
Let me know if i missed anything.
Co-authored-by: Felix Arntz <[email protected]>
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.
LGTM. Smoke tested locally. Tests pass and logs are clean.
Thanks!
Let me know if you need help backporting to the plugin.
Yes please if you have moment. Thanks |
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've given this one a quick test as well. LGTM too.
As part of the testing I also ran through the various means of defining block style variations (theme.json partials, register_block_style etc). All the variations displayed correctly, could be modified in global styles, and had updates reflected appropriately on the frontend.
LGTM too.
I'll give the plugin backport a run shortly.
…block_style_variations() for better performance (#66539) * Backporting theme json performance optimizations from WordPress/wordpress-develop#7586 * Tentatively backport using `get_blocks_metadata` instead of `WP_Block_Type_Registry` to get block names. Co-authored-by: ramonjd <[email protected]> Co-authored-by: mukeshpanchal27 <[email protected]> Co-authored-by: aaronrobertshaw <[email protected]>
…block_style_variations() for better performance (#66539) * Backporting theme json performance optimizations from WordPress/wordpress-develop#7586 * Tentatively backport using `get_blocks_metadata` instead of `WP_Block_Type_Registry` to get block names. Co-authored-by: ramonjd <[email protected]> Co-authored-by: mukeshpanchal27 <[email protected]> Co-authored-by: aaronrobertshaw <[email protected]> Source: WordPress/gutenberg@828868d
Is this ready to be committed? The Gutenberg backport PR is merged. |
Yes. If you have moment then commit it. |
…block_style_variations() for better performance (WordPress#66539) * Backporting theme json performance optimizations from WordPress/wordpress-develop#7586 * Tentatively backport using `get_blocks_metadata` instead of `WP_Block_Type_Registry` to get block names. Co-authored-by: ramonjd <[email protected]> Co-authored-by: mukeshpanchal27 <[email protected]> Co-authored-by: aaronrobertshaw <[email protected]>
Trac Ticket: https://core.trac.wordpress.org/ticket/62291