mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Improve performance of WP_Theme_JSON::merge
when merging background styles
#7486
Closed
mukeshpanchal27
wants to merge
14
commits into
WordPress:trunk
from
mukeshpanchal27:fix/61858-performance-regression
Closed
Changes from 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c13a398
Improve performance
mukeshpanchal27 2b7be60
Merge branch 'WordPress:trunk' into fix/61858-performance-regression
mukeshpanchal27 46640a7
Introduce get_block_node_paths()
mukeshpanchal27 76e0140
Add options that include node path and block elements
mukeshpanchal27 82dc69a
Apply suggestions from code review
mukeshpanchal27 867ae4a
Remove "include_block_elements" parameter
mukeshpanchal27 dbbd010
Address review feedbacks
mukeshpanchal27 bdf769c
Merge branch 'WordPress:trunk' into fix/61858-performance-regression
mukeshpanchal27 2adb26a
Remove variable
mukeshpanchal27 58dfa83
Update new variable description
mukeshpanchal27 35e4ed4
Unit tests for new changes
mukeshpanchal27 f1237f8
Merge branch 'trunk' into fix/61858-performance-regression
felixarntz 115dc4e
Add since annotation for the method change.
felixarntz 0eb736b
Move option variable assignments before the loops.
felixarntz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3101,6 +3101,53 @@ protected static function get_metadata_boolean( $data, $path, $default_value = f | |
return $default_value; | ||
} | ||
|
||
/** | ||
* An internal method to get the block nodes from a theme.json file. | ||
* | ||
* @since 6.7.0 | ||
* | ||
* @param array $theme_json The theme.json converted to an array. | ||
* @return array The block nodes in theme.json. | ||
*/ | ||
private static function get_block_node_paths( $theme_json ) { | ||
$nodes = array(); | ||
if ( ! isset( $theme_json['styles'] ) ) { | ||
return $nodes; | ||
} | ||
|
||
// Blocks. | ||
if ( ! isset( $theme_json['styles']['blocks'] ) ) { | ||
return $nodes; | ||
} | ||
|
||
foreach ( $theme_json['styles']['blocks'] as $name => $node ) { | ||
$nodes[] = array( | ||
'path' => array( 'styles', 'blocks', $name ), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like incorrect indentation? Same below. |
||
); | ||
|
||
if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'] ) ) { | ||
foreach ( $theme_json['styles']['blocks'][ $name ]['elements'] as $element => $node ) { | ||
$nodes[] = array( | ||
'path' => array( 'styles', 'blocks', $name, 'elements', $element ), | ||
); | ||
|
||
// Handle any pseudo selectors for the element. | ||
if ( isset( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] ) ) { | ||
foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] as $pseudo_selector ) { | ||
if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'][ $element ][ $pseudo_selector ] ) ) { | ||
$nodes[] = array( | ||
'path' => array( 'styles', 'blocks', $name, 'elements', $element ), | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return $nodes; | ||
} | ||
|
||
/** | ||
* Merges new incoming data. | ||
* | ||
|
@@ -3236,7 +3283,7 @@ public function merge( $incoming ) { | |
* some values provide exceptions, namely style values that are | ||
* objects and represent unique definitions for the style. | ||
*/ | ||
$style_nodes = static::get_styles_block_nodes(); | ||
$style_nodes = static::get_block_node_paths( $this->theme_json ); | ||
foreach ( $style_nodes as $style_node ) { | ||
$path = $style_node['path']; | ||
mukeshpanchal27 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/* | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Given this is a separate function with the only purpose to return the node paths, it would make more sense to return an array of strings, not an array of associative node arrays with only the path in it.
But we may want to reconsider the approach, per my overarching comment.