mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
Multisite: Improve performance by caching not found lookups for sites and networks.
With this change, the result of a site or network lookup by ID will be cached even if the ID does not exist. When a new site or network is created, the cache for the respective new ID is cleared. Props mnelson4, nielsdeblaauw. Fixes #42251. Built from https://develop.svn.wordpress.org/trunk@45910 git-svn-id: http://core.svn.wordpress.org/trunk@45721 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
ccdc221b32
commit
90c424f73b
@ -1159,6 +1159,12 @@ function populate_network_meta( $network_id, array $meta = array() ) {
|
||||
}
|
||||
}
|
||||
|
||||
if ( function_exists( 'clean_network_cache' ) ) {
|
||||
clean_network_cache( $network_id );
|
||||
} else {
|
||||
wp_cache_delete( $network_id, 'networks' );
|
||||
}
|
||||
|
||||
wp_cache_delete( 'networks_have_paths', 'site-options' );
|
||||
|
||||
if ( ! is_multisite() ) {
|
||||
|
@ -101,16 +101,20 @@ class WP_Network {
|
||||
|
||||
$_network = wp_cache_get( $network_id, 'networks' );
|
||||
|
||||
if ( ! $_network ) {
|
||||
if ( false === $_network ) {
|
||||
$_network = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->site} WHERE id = %d LIMIT 1", $network_id ) );
|
||||
|
||||
if ( empty( $_network ) || is_wp_error( $_network ) ) {
|
||||
return false;
|
||||
$_network = -1;
|
||||
}
|
||||
|
||||
wp_cache_add( $network_id, $_network, 'networks' );
|
||||
}
|
||||
|
||||
if ( is_numeric( $_network ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return new WP_Network( $_network );
|
||||
}
|
||||
|
||||
@ -231,8 +235,8 @@ class WP_Network {
|
||||
return (int) $this->blog_id;
|
||||
}
|
||||
|
||||
if ( ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) && $this->domain === DOMAIN_CURRENT_SITE && $this->path === PATH_CURRENT_SITE )
|
||||
|| ( defined( 'SITE_ID_CURRENT_SITE' ) && $this->id == SITE_ID_CURRENT_SITE ) ) {
|
||||
if ( ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) && DOMAIN_CURRENT_SITE === $this->domain && PATH_CURRENT_SITE === $this->path )
|
||||
|| ( defined( 'SITE_ID_CURRENT_SITE' ) && SITE_ID_CURRENT_SITE == $this->id ) ) {
|
||||
if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) {
|
||||
$this->blog_id = (string) BLOG_ID_CURRENT_SITE;
|
||||
|
||||
@ -457,7 +461,7 @@ class WP_Network {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( $network->path === '/' ) {
|
||||
if ( '/' === $network->path ) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
|
@ -162,16 +162,20 @@ final class WP_Site {
|
||||
|
||||
$_site = wp_cache_get( $site_id, 'sites' );
|
||||
|
||||
if ( ! $_site ) {
|
||||
if ( false === $_site ) {
|
||||
$_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d LIMIT 1", $site_id ) );
|
||||
|
||||
if ( empty( $_site ) || is_wp_error( $_site ) ) {
|
||||
return false;
|
||||
$_site = -1;
|
||||
}
|
||||
|
||||
wp_cache_add( $site_id, $_site, 'sites' );
|
||||
}
|
||||
|
||||
if ( is_numeric( $_site ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return new WP_Site( $_site );
|
||||
}
|
||||
|
||||
|
@ -69,14 +69,14 @@ function wp_insert_site( array $data ) {
|
||||
return new WP_Error( 'db_insert_error', __( 'Could not insert site into the database.' ), $wpdb->last_error );
|
||||
}
|
||||
|
||||
clean_blog_cache( $wpdb->insert_id );
|
||||
|
||||
$new_site = get_site( $wpdb->insert_id );
|
||||
|
||||
if ( ! $new_site ) {
|
||||
return new WP_Error( 'get_site_error', __( 'Could not retrieve site data.' ) );
|
||||
}
|
||||
|
||||
clean_blog_cache( $new_site );
|
||||
|
||||
/**
|
||||
* Fires once a site has been inserted into the database.
|
||||
*
|
||||
|
@ -13,7 +13,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.3-alpha-45909';
|
||||
$wp_version = '5.3-alpha-45910';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user