Multisite load: Cache the main site lookup query.

props jeremyfelt.
see #27003.

Built from https://develop.svn.wordpress.org/trunk@27664


git-svn-id: http://core.svn.wordpress.org/trunk@27507 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2014-03-24 01:01:15 +00:00
parent 1bacefa353
commit e14237a109
1 changed files with 2 additions and 2 deletions

View File

@ -172,10 +172,10 @@ if ( !isset( $current_site ) || !isset( $current_blog ) ) {
if ( ! isset( $current_site->blog_id ) ) { if ( ! isset( $current_site->blog_id ) ) {
if ( $current_blog->domain === $current_site->domain && $current_blog->path === $current_site->path ) { if ( $current_blog->domain === $current_site->domain && $current_blog->path === $current_site->path ) {
$current_site->blog_id = $current_blog->blog_id; $current_site->blog_id = $current_blog->blog_id;
} else { } elseif ( ! $current_site->blog_id = wp_cache_get( 'network:' . $current_site->id . ':main_site', 'site-options' ) ) {
// @todo we should be able to cache the blog ID of a network's main site easily.
$current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s", $current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s",
$current_site->domain, $current_site->path ) ); $current_site->domain, $current_site->path ) );
wp_cache_add( 'network:' . $current_site->id . ':main_site', $current_site->blog_id, 'site-options' );
} }
} }