-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Update: Improve performance of gutenberg_render_layout_support_flag. #46074
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
Changes from 1 commit
f7027e5
a16c4dd
cd4e43d
d5f575f
f40ba0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -370,17 +370,25 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { | |
| return (string) $content; | ||
| } | ||
|
|
||
| $block_gap = gutenberg_get_global_settings( array( 'spacing', 'blockGap' ) ); | ||
| $global_layout_settings = gutenberg_get_global_settings( array( 'layout' ) ); | ||
| $has_block_gap_support = isset( $block_gap ) ? null !== $block_gap : false; | ||
| static $static_information_computed = false; | ||
| static $has_block_gap_support = false; | ||
| static $global_layout_settings = null; | ||
| static $root_padding_aware_alignments = false; | ||
| if ( ! $static_information_computed ) { | ||
| $global_settings = gutenberg_get_global_settings(); | ||
| $block_gap = _wp_array_get( $global_settings, array( 'spacing', 'blockGap' ), $global_settings ); | ||
jorgefilipecosta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $has_block_gap_support = isset( $block_gap ); | ||
|
||
| $global_layout_settings = _wp_array_get( $global_settings, array( 'layout' ), $global_settings ); | ||
jorgefilipecosta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $root_padding_aware_alignments = _wp_array_get( $global_settings, array( 'useRootPaddingAwareAlignments' ), $global_settings ); | ||
jorgefilipecosta marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $static_information_computed = true; | ||
| } | ||
|
|
||
| $default_block_layout = _wp_array_get( $block_type->supports, array( '__experimentalLayout', 'default' ), array() ); | ||
| $used_layout = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : $default_block_layout; | ||
|
|
||
| if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] ) { | ||
| if ( ! $global_layout_settings ) { | ||
| if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] && ! $global_layout_settings ) { | ||
| return $block_content; | ||
aristath marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| $class_names = array(); | ||
| $layout_definitions = _wp_array_get( $global_layout_settings, array( 'definitions' ), array() ); | ||
|
|
@@ -393,7 +401,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { | |
| } | ||
|
|
||
| if ( | ||
| gutenberg_get_global_settings( array( 'useRootPaddingAwareAlignments' ) ) && | ||
| $root_padding_aware_alignments && | ||
| isset( $used_layout['type'] ) && | ||
| 'constrained' === $used_layout['type'] | ||
| ) { | ||
|
|
||
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.
Can we add a comment here to describe why we cache this data at render time, so future readers understand why this is set up in this way?
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.
How is the cache invalidation?
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.
Looking at this code closer, I think we should remove this cache all together. Caching of global settings should be done here - #45372. Cache invalidation should also be done here. That way we can call
gutenberg_get_global_settingswithout worrying parsing again.The worry here is double caching and cache invalidation.
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.
@spacedmonkey How is cache invalidation relevant for this change? I'm not sure I understand.
Since this PR uses a simple "variable cache" (i.e. in PHP runtime memory), I wouldn't think cache invalidation for this matters (since it's not using
WP_Object_Cacheand the data here is static).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.
@felixarntz What if a filter or register theme support changes something in the runtime? How is this runtime cache invalidated?