Make WordPress Core

Ticket #46388: 46388.diff

File 46388.diff, 851 bytes (added by Asgaros, 4 years ago)

Add patch file for caching of non-existent users

  • src/wp-includes/class-wp-user.php

     
    233233                }
    234234
    235235                if ( false !== $user_id ) {
     236                        // Prevent non-existent users from triggering multiple queries
     237                        $notusers = wp_cache_get( 'notusers', 'users' );
     238                        if ( isset( $notusers[ $user_id ] ) ) {
     239                                return false;
     240                        }
     241
    236242                        if ( $user = wp_cache_get( $user_id, 'users' ) ) {
    237243                                return $user;
    238244                        }
     
    244250                                $value
    245251                        )
    246252                ) ) {
     253                        // User does not exist, so we must cache its non-existence
     254                        if ( ! is_array( $notusers ) ) {
     255                                $notusers = array();
     256                        }
     257
     258                        $notusers[ $user_id ] = true;
     259                        wp_cache_set( 'notusers', $notusers, 'users' );
     260                       
    247261                        return false;
    248262                }
    249263