Networks and Sites: Store main site id of a network in network options.

Instead of caching main site id an object cache, store main site id on a network options. This results in less database queries on sites without persistent object caching. 

Props spacedmonkey, johnjamesjacoby, peterwilsoncc, desrosj.
Fixes #55802.
Built from https://develop.svn.wordpress.org/trunk@54256


git-svn-id: http://core.svn.wordpress.org/trunk@53815 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
spacedmonkey 2022-09-20 14:26:10 +00:00
parent 5dcad0a618
commit da4456672c
3 changed files with 13 additions and 4 deletions

View File

@ -1068,6 +1068,16 @@ function populate_network( $network_id = 1, $domain = '', $email = '', $site_nam
update_user_meta( $site_user->ID, 'source_domain', $domain ); update_user_meta( $site_user->ID, 'source_domain', $domain );
update_user_meta( $site_user->ID, 'primary_blog', $current_site->blog_id ); update_user_meta( $site_user->ID, 'primary_blog', $current_site->blog_id );
// Unable to use update_network_option() while populating the network.
$wpdb->insert(
$wpdb->sitemeta,
array(
'site_id' => $network_id,
'meta_key' => 'main_site',
'meta_value' => $current_site->blog_id,
)
);
if ( $subdomain_install ) { if ( $subdomain_install ) {
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
} else { } else {

View File

@ -255,9 +255,8 @@ class WP_Network {
if ( $site->domain === $this->domain && $site->path === $this->path ) { if ( $site->domain === $this->domain && $site->path === $this->path ) {
$main_site_id = (int) $site->id; $main_site_id = (int) $site->id;
} else { } else {
$cache_key = 'network:' . $this->id . ':main_site';
$main_site_id = wp_cache_get( $cache_key, 'site-options' ); $main_site_id = get_network_option( $this->id, 'main_site' );
if ( false === $main_site_id ) { if ( false === $main_site_id ) {
$_sites = get_sites( $_sites = get_sites(
array( array(
@ -270,7 +269,7 @@ class WP_Network {
); );
$main_site_id = ! empty( $_sites ) ? array_shift( $_sites ) : 0; $main_site_id = ! empty( $_sites ) ? array_shift( $_sites ) : 0;
wp_cache_add( $cache_key, $main_site_id, 'site-options' ); update_network_option( $this->id, 'main_site', $main_site_id );
} }
} }

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.1-alpha-54255'; $wp_version = '6.1-alpha-54256';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.