WordPress.org

Make WordPress Core

Ticket #27003: 27003.23.diff

File 27003.23.diff, 1.1 KB (added by jeremyfelt, 6 years ago)
  • src/wp-includes/ms-settings.php

     
    124124                if ( $current_blog && $current_blog->domain === $current_site->domain && $current_blog->path === $current_site->path ) {
    125125                        $current_site->blog_id = $current_blog->blog_id;
    126126                } else {
    127                         // @todo we should be able to cache the blog ID of a network's main site easily.
    128                         $current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s",
    129                                 $current_site->domain, $current_site->path ) );
     127                        if ( ! $current_site->blog_id = wp_cache_get( 'network_' . $current_site->id . '_blog_id', 'site-options' ) ) {
     128                                $current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s",
     129                                        $current_site->domain, $current_site->path ) );
     130                                wp_cache_add( 'network_' . $current_site->id . '_blog_id', $current_site->blog_id, 'site-options' );
     131                        }
    130132                }
    131133        }
    132134