-
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
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 1 commit
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`
7450d26
The values of the args are only useful for the cache key
c9b36ea
Deal with cache before updating `$properties`
dd8c83e
Only use cache if not in dev mode for theme. Ensure we do not process…
7d97433
Address PHPCS warning. It really does not matter if the value of `$pr…
bd6f08c
Merge branch 'WordPress:trunk' into add/object-cache-compute-style-pr…
pereirinha 2377348
Remove unecessary dev mode check for cache
d707a79
Add the global settings to the cache key recipe, so that when it chan…
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
Prev
Previous commit
Add the global settings to the cache key recipe, so that when it chan…
…ges, it invalidates the cache
- Loading branch information
There are no files selected for viewing
This file contains hidden or 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,7 +1934,8 @@ protected static function compute_style_properties( $styles, $settings = array() | |||||
| return $declarations; | ||||||
| } | ||||||
|
|
||||||
| $args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.Changed | ||||||
| // The global settings can include dynamic data related to typography. We need evaluate it so that the cache is invalidated when it changes. | ||||||
| $args = array( func_get_args(), wp_get_global_settings() ); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.Changed | ||||||
| $cache_key = 'compute_style_properties_' . md5( wp_json_encode( $args ) ); | ||||||
| $cache = wp_cache_get( $cache_key, 'wp-styles' ); | ||||||
|
Member
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
|
||||||
|
|
||||||
|
|
||||||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
The way the theme.json code is organized is as follows:
WP_Theme_JSON: private class that deals with atheme.jsonstructure. It doesn't depend on anything else.WP_Theme_JSON_Resolver: private class that pulls data (theme.json files, theme.json from database) and merges it together appropriately (get_merged_data). It depends on theWP_Theme_JSONclass.wp_get_global_settings,wp_get_global_styles, etc. They use and depend on the two previous private classes.By using a public function such as
wp_get_global_settingsin theWP_Theme_JSONclass, this code is creating a circular dependency. This code is saying: when processing any theme.json structure, read all existing theme.json (core, blocks, theme, user) first.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.
Thanks for the feedback @oandregal. This makes perfect sense. I think we would either need to add the caching to the public function that relies on
WP_Theme_JSON::compute_style_propertiesor find a different approach to invalidation withinWP_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.
Thanks for the feedback @oandregal. I'll have a closer look at this