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.

git-svn-id: https://develop.svn.wordpress.org/trunk@54256 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonny Harris
2022-09-20 14:24:08 +00:00
parent 0cfcb3e272
commit f158620eab
3 changed files with 23 additions and 3 deletions
+2 -3
View File
@@ -255,9 +255,8 @@ class WP_Network {
if ( $site->domain === $this->domain && $site->path === $this->path ) {
$main_site_id = (int) $site->id;
} 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 ) {
$_sites = get_sites(
array(
@@ -270,7 +269,7 @@ class WP_Network {
);
$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 );
}
}