Make WordPress Core


Ignore:
Timestamp:
09/20/2022 02:24:08 PM (2 years ago)
Author:
spacedmonkey
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-network.php

    r54133 r54256  
    256256            $main_site_id = (int) $site->id;
    257257        } else {
    258             $cache_key = 'network:' . $this->id . ':main_site';
    259 
    260             $main_site_id = wp_cache_get( $cache_key, 'site-options' );
     258
     259            $main_site_id = get_network_option( $this->id, 'main_site' );
    261260            if ( false === $main_site_id ) {
    262261                $_sites       = get_sites(
     
    271270                $main_site_id = ! empty( $_sites ) ? array_shift( $_sites ) : 0;
    272271
    273                 wp_cache_add( $cache_key, $main_site_id, 'site-options' );
     272                update_network_option( $this->id, 'main_site', $main_site_id );
    274273            }
    275274        }
Note: See TracChangeset for help on using the changeset viewer.