mirrored from git://develop.git.wordpress.org/
-
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
Add object caching for WP_Theme_JSON::compute_style_properties
#5567
Open
pereirinha
wants to merge
8
commits into
WordPress:trunk
Choose a base branch
from
pereirinha:add/object-cache-compute-style-properties
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
85e9170
Add object caching for `WP_Theme_JSON::compute_style_properties`
pereirinha 7450d26
The values of the args are only useful for the cache key
pereirinha c9b36ea
Deal with cache before updating `$properties`
pereirinha dd8c83e
Only use cache if not in dev mode for theme. Ensure we do not process…
pereirinha 7d97433
Address PHPCS warning. It really does not matter if the value of `$pr…
pereirinha bd6f08c
Merge branch 'WordPress:trunk' into add/object-cache-compute-style-pr…
pereirinha 2377348
Remove unecessary dev mode check for cache
pereirinha d707a79
Add the global settings to the cache key recipe, so that when it chan…
pereirinha 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 | ||||
---|---|---|---|---|---|---|
|
@@ -1934,6 +1934,16 @@ protected static function compute_style_properties( $styles, $settings = array() | |||||
return $declarations; | ||||||
} | ||||||
|
||||||
$can_use_cached = ! wp_is_development_mode( 'theme' ); | ||||||
|
||||||
$args = func_get_args(); | ||||||
$cache_key = 'compute_style_properties_' . md5( wp_json_encode( $args ) ); | ||||||
$cache = wp_cache_get( $cache_key, 'wp-styles' ); | ||||||
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. Rather than introducing a new cache group, I think this should be a part of the existing
Suggested change
|
||||||
|
||||||
if ( $can_use_cached && $cache ) { | ||||||
return $cache; | ||||||
} | ||||||
|
||||||
$root_variable_duplicates = array(); | ||||||
|
||||||
foreach ( $properties as $css_property => $value_path ) { | ||||||
|
@@ -2000,6 +2010,10 @@ protected static function compute_style_properties( $styles, $settings = array() | |||||
} | ||||||
} | ||||||
|
||||||
if ( $can_use_cached ) { | ||||||
wp_cache_set( $cache_key, $declarations, 'wp-styles', DAY_IN_SECONDS ); | ||||||
} | ||||||
|
||||||
return $declarations; | ||||||
} | ||||||
|
||||||
|
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.
As far as I can tell, we may be able to avoid the
wp_is_development_mode()
check here entirely. Here's why:wp_get_typography_font_size_value()
below, which relies on other data (e.g.wp_get_global_settings()
). So maybe we can cache everything except that one? Would that still be beneficial for performance?That would mean that we cache the result of the foreach loop, except for the
font-size
CSS property we simply store the$value
without callingwp_get_typography_font_size_value()
.After that loop, even if we got the result from cache, we can cycle through the loop of the results and call
wp_get_typography_font_size_value()
for any entry that is using thefont-size
CSS property.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
I agree that the check for the development mode here doesn't bring any value. For that reason, I removed it.
As for your concern around
wp_get_global_settings()
for the case when users tweak values, I think that we can get away with making that part of the recipe for the cache key. Here's how.What do you think?