WordPress.org

Make WordPress Core


Ignore:
Timestamp:
08/29/2019 12:41:45 PM (3 weeks 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-site.php

    r45232 r45910  
    163163        $_site = wp_cache_get( $site_id, 'sites' );
    164164
    165         if ( ! $_site ) {
     165        if ( false === $_site ) {
    166166            $_site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->blogs} WHERE blog_id = %d LIMIT 1", $site_id ) );
    167167
    168168            if ( empty( $_site ) || is_wp_error( $_site ) ) {
    169                 return false;
     169                $_site = -1;
    170170            }
    171171
    172172            wp_cache_add( $site_id, $_site, 'sites' );
     173        }
     174
     175        if ( is_numeric( $_site ) ) {
     176            return false;
    173177        }
    174178
Note: See TracChangeset for help on using the changeset viewer.