mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00: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. git-svn-id: https://develop.svn.wordpress.org/trunk@45910 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user