-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add object caching for WP_Theme_JSON::compute_style_properties
#5567
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
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' ); | ||||||
|
||||||
| $cache = wp_cache_get( $cache_key, 'wp-styles' ); | |
| $cache = wp_cache_get( $cache_key, 'theme_json' ); |
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-sizeCSS property we simply store the$valuewithout 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-sizeCSS 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?