Make WordPress Core


Ignore:
Timestamp:
08/29/2019 12:41:45 PM (5 years ago)
Author:
flixos90
Message:

Multisite: Improve performance by caching not found lookups for sites and networks.

With this change, the result of a site or network lookup by ID will be cached even if the ID does not exist. When a new site or network is created, the cache for the respective new ID is cleared.

Props mnelson4, nielsdeblaauw.
Fixes #42251.

File:
1 edited

Legend:

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

    r42876 r45910  
    102102        $_network = wp_cache_get( $network_id, 'networks' );
    103103
    104         if ( ! $_network ) {
     104        if ( false === $_network ) {
    105105            $_network = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->site} WHERE id = %d LIMIT 1", $network_id ) );
    106106
    107107            if ( empty( $_network ) || is_wp_error( $_network ) ) {
    108                 return false;
     108                $_network = -1;
    109109            }
    110110
    111111            wp_cache_add( $network_id, $_network, 'networks' );
     112        }
     113
     114        if ( is_numeric( $_network ) ) {
     115            return false;
    112116        }
    113117
     
    232236        }
    233237
    234         if ( ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) && $this->domain === DOMAIN_CURRENT_SITE && $this->path === PATH_CURRENT_SITE )
    235             || ( defined( 'SITE_ID_CURRENT_SITE' ) && $this->id == SITE_ID_CURRENT_SITE ) ) {
     238        if ( ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) && DOMAIN_CURRENT_SITE === $this->domain && PATH_CURRENT_SITE === $this->path )
     239            || ( defined( 'SITE_ID_CURRENT_SITE' ) && SITE_ID_CURRENT_SITE == $this->id ) ) {
    236240            if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) {
    237241                $this->blog_id = (string) BLOG_ID_CURRENT_SITE;
     
    458462                }
    459463            }
    460             if ( $network->path === '/' ) {
     464            if ( '/' === $network->path ) {
    461465                $found = true;
    462466                break;
Note: See TracChangeset for help on using the changeset viewer.