Make WordPress Core

Opened 5 years ago

Last modified 2 months ago

#55454 new defect (bug)

clean_site_details_cache() doesn't clean all site caches

Reported by: dd32 Owned by:
Priority: low Milestone: Awaiting Review
Component: Networks and Sites Version: 4.7
Severity: minor Keywords:
Cc: Focuses: multisite

Description

clean_site_details_cache() clear's two caches:

	wp_cache_delete( $site_id, 'site-details' );
	wp_cache_delete( $site_id, 'blog-details' );

​https://github.com/WordPress/wordpress-develop/blob/0b800e21c311e302824e4a025946a6fdb4f6c794/src/wp-includes/ms-blogs.php#L322-L337

But there's a third used within get_blog_details() that's closely related to those two caches:

	if ( $get_all ) {
		$details = wp_cache_get( $blog_id . 'short', 'blog-details' );
	} else {
		$details = wp_cache_get( $blog_id, 'blog-details' );

One could argue that the blog-details caches are not related to the site-details caches, but one would expect that if it clears some of them, that it'll clear all of them.

clean_blog_cache() is a ​much more comprehensive function though:

	wp_cache_delete( $blog_id, 'sites' );
	wp_cache_delete( $blog_id, 'site-details' );
	wp_cache_delete( $blog_id, 'blog-details' );
	wp_cache_delete( $blog_id . 'short', 'blog-details' );
	wp_cache_delete( $domain_path_key, 'blog-lookup' );
	wp_cache_delete( $domain_path_key, 'blog-id-cache' );
	wp_cache_delete( $blog_id, 'blog_meta' );

Change History (3)

#1 @sabernhardt
4 years ago

#55455 was marked as a duplicate.

This ticket was mentioned in ​Slack in #core-multisite by realloc. ​View the logs.


17 months ago

#3 @realloc
2 months ago

clean_site_details_cache() only ever runs when one of four options changes: blogname, siteurl, post_count, home. That is worth keeping in mind, because the two caches it misses are not in the same situation.

The short entry never stores those four values in the first place. It is a plain row from the blogs table, and anything asking it for a blog name is quietly redirected to the site-details cache, which the function does clear. So adding it would make the function tidier and match what get_blog_details() reads, but nothing is actually wrong today.

The lookup-by-domain cache is the real problem. When a site is fetched by domain and path, the four option values are baked into the cached object, and the next lookup hands that object straight back without checking anything. Rename a site and the old name keeps coming back from that path until something else clears the cache.

Fixing that one is slightly more than a one-liner: the cache key is built from domain and path, which the function does not currently have, so it would need to load the site first.

Refs:

  • callers ms-default-filters.php:124-127
  • short writes ms-blogs.php:152, :170, :242, ms-site.php:402-406
  • fallthrough class-wp-site.php:239-250
  • blog-lookup write ms-blogs.php:253-256, :275, read :141-144
Note: See TracTickets for help on using tickets.