Skip to content
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

Improved caching. #3624

Closed
wants to merge 6 commits into from
Closed

Conversation

spacedmonkey
Copy link
Member

Trac ticket: https://core.trac.wordpress.org/ticket/57077


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spacedmonkey I like where this is going, but currently there are 2 concerns where the updated logic would break current behavior.

src/wp-includes/class-wp-theme-json-resolver.php Outdated Show resolved Hide resolved
@peterwilsoncc
Copy link
Contributor

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spacedmonkey Production code looks good (just 2 nit-picks below), though as @peterwilsoncc there are some test fixes we need to make.

We should also add at least one new test to cover the new caching layer here to make sure it caches correctly.

src/wp-includes/class-wp-theme-json-resolver.php Outdated Show resolved Hide resolved
src/wp-includes/class-wp-theme-json-resolver.php Outdated Show resolved Hide resolved
@spacedmonkey
Copy link
Member Author

@peterwilsoncc A simple workaround is to call, clean theme json caches, on add_theme_support and remove_theme_supports.

@spacedmonkey
Copy link
Member Author

@felixarntz @peterwilsoncc Spent some time on this PR. Caching block settings is harder than you might think. Block settings contain lots of calls to get_theme_supports. So if a theme support is added / removed, the cached value is incorrect. As developer can and do, remove / add theme supports. To work around this, I have added two new actions and then clean caches for theme json with callback.

I don't love this, but I don't see anyway around this.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spacedmonkey I'm not sure the new code here is the way we should go. I agree this is a problem, but I think we need to come up with a better solution, since IMO now it introduces a new problem, by invalidating cache on every add_theme_support call.

Can we move the logic for where the theme support is used for to happen after cache? Or, at a minimum, at least only invalidate the cache that uses theme support instead of all caches in that class?

add_action( 'after_switch_theme', '_wp_menus_changed' );
add_action( 'after_switch_theme', '_wp_sidebars_changed' );
add_action( 'wp_print_styles', 'print_emoji_styles' );
add_action( 'plugins_loaded', '_wp_theme_json_webfonts_handler' );

foreach ( array( 'switch_theme', 'start_previewing_theme', 'add_theme_support', 'remove_theme_support' ) as $action ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the add_theme_support and remove_theme_support integration should be removed. I understand the concern, and I agree this is a problem we need to address.

However, invalidating the cache on add_theme_support means that it will happen on every request, since that function is typically called in every request.

Addressing this problem is not easy, which is why we need to IMO take some more time to think about the best way to address it. The root problem is that data that is cached preferably shouldn't depend on add_theme_support or any filters FWIW.

@spacedmonkey
Copy link
Member Author

@felixarntz I agree, I think this PR is a little bit of a none starter for now. I think we may have to refactor this logic so it is easier to invalidate.

@spacedmonkey
Copy link
Member Author

Closing as this PR is a none starter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants