-
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
base: trunk
Are you sure you want to change the base?
Changes from 5 commits
85e9170
7450d26
c9b36ea
dd8c83e
7d97433
bd6f08c
2377348
d707a79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.Changed | ||||||
$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. This code is still being called if the theme is in development mode. Could you please review the approach taken in this section of the code and consider applying a similar approach here? 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; | ||||||
} | ||||||
|
||||||
|
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?