WordPress.org

Make WordPress Core

Changeset 40385


Ignore:
Timestamp:
04/06/17 17:26:04 (3 weeks ago)
Author:
swissspidy
Message:

Multisite: Handle sites cache invalidation more granularly for option updates.

Previously update_blog_option() would trigger an invalidation of that site's entire cache although these changes did not affect the content of
these caches. Furthermore changes to the special options blogname, siteurl and post_count should not invalidate the entire cache of that site, but only their respective site details cache. The option home now has the same behavior as it also belongs to the site details, but did not invalidate the cache at all previously.

Several new unit tests confirm these changes work as expected.

Fixes #40063.

Merges [40305] and [40333] to the 4.7 branch.

Location:
branches/4.7
Files:
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/4.7

  • branches/4.7/src/wp-includes/ms-blogs.php

    r39082 r40385  
    471471 
    472472    wp_cache_set( 'last_changed', microtime(), 'sites' ); 
     473} 
     474 
     475/** 
     476 * Cleans the site details cache for a site. 
     477 * 
     478 * @since 4.7.4 
     479 * 
     480 * @param int $site_id Optional. Site ID. Default is the current site ID. 
     481 */ 
     482function clean_site_details_cache( $site_id = 0 ) { 
     483    $site_id = (int) $site_id; 
     484    if ( ! $site_id ) { 
     485        $site_id = get_current_blog_id(); 
     486    } 
     487 
     488    wp_cache_delete( $site_id, 'site-details' ); 
     489    wp_cache_delete( $site_id, 'blog-details' ); 
    473490} 
    474491 
     
    737754    restore_current_blog(); 
    738755 
    739     refresh_blog_details( $id ); 
    740  
    741756    return $return; 
    742757} 
  • branches/4.7/src/wp-includes/ms-default-filters.php

    r34251 r40385  
    8585remove_filter( 'option_home',    '_config_wp_home'    ); 
    8686 
    87 // Some options changes should trigger blog details refresh. 
    88 add_action( 'update_option_blogname',   'refresh_blog_details', 10, 0 ); 
    89 add_action( 'update_option_siteurl',    'refresh_blog_details', 10, 0 ); 
    90 add_action( 'update_option_post_count', 'refresh_blog_details', 10, 0 ); 
     87// Some options changes should trigger site details refresh. 
     88add_action( 'update_option_blogname',   'clean_site_details_cache', 10, 0 ); 
     89add_action( 'update_option_siteurl',    'clean_site_details_cache', 10, 0 ); 
     90add_action( 'update_option_post_count', 'clean_site_details_cache', 10, 0 ); 
     91add_action( 'update_option_home',       'clean_site_details_cache', 10, 0 ); 
    9192 
    9293// If the network upgrade hasn't run yet, assume ms-files.php rewriting is used. 
Note: See TracChangeset for help on using the changeset viewer.