mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 12:50:28 +00:00
Update: Improve performance of gutenberg_render_layout_support_flag.
Backports https://github.com/WordPress/gutenberg/pull/46074 into the core. render_layout_support_flag is run per block, and inside we called get_global_settings three times. get_global_settings calls get_merged_data, which is costly. render_layout_support_flag is a filter called during the block render. When the blocks start rendering, there is no expectation that the theme.json settings change during the block render, so the settings and their derived information should all be static information of this function. This simple change removes 3*NUMBER_OF_BLOCKS calls of get_merged_data to just one call. Props oandregal, aristath, felixarntz, tellthemachines, andrewserong, aaronrobertshaw, aaronrobertshaw. git-svn-id: https://develop.svn.wordpress.org/trunk@55167 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -316,16 +316,17 @@ function wp_render_layout_support_flag( $block_content, $block ) {
|
||||
return $block_content;
|
||||
}
|
||||
|
||||
$block_gap = wp_get_global_settings( array( 'spacing', 'blockGap' ) );
|
||||
$global_layout_settings = wp_get_global_settings( array( 'layout' ) );
|
||||
$has_block_gap_support = isset( $block_gap ) ? null !== $block_gap : false;
|
||||
$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;
|
||||
$global_settings = wp_get_global_settings();
|
||||
$block_gap = _wp_array_get( $global_settings, array( 'spacing', 'blockGap' ), null );
|
||||
$has_block_gap_support = isset( $block_gap );
|
||||
$global_layout_settings = _wp_array_get( $global_settings, array( 'layout' ), null );
|
||||
$root_padding_aware_alignments = _wp_array_get( $global_settings, array( 'useRootPaddingAwareAlignments' ), false );
|
||||
|
||||
if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] ) {
|
||||
if ( ! $global_layout_settings ) {
|
||||
return $block_content;
|
||||
}
|
||||
$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'] && ! $global_layout_settings ) {
|
||||
return $block_content;
|
||||
}
|
||||
|
||||
$class_names = array();
|
||||
@@ -340,7 +341,7 @@ function wp_render_layout_support_flag( $block_content, $block ) {
|
||||
}
|
||||
|
||||
if (
|
||||
wp_get_global_settings( array( 'useRootPaddingAwareAlignments' ) ) &&
|
||||
$root_padding_aware_alignments &&
|
||||
isset( $used_layout['type'] ) &&
|
||||
'constrained' === $used_layout['type']
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user