Make WordPress Core

Ticket #21120: 21120.diff

File 21120.diff, 671 bytes (added by kurtpayne, 12 years ago)

Proof of concept static cache

  • wp-includes/pluggable.php

    diff --git wp-includes/pluggable.php wp-includes/pluggable.php
    index ac308a9..11d769f 100644
    if ( !function_exists('get_user_by') ) : 
    133133 * @return bool|object False on failure, WP_User object on success
    134134 */
    135135function get_user_by( $field, $value ) {
     136        static $cache = array();
    136137        $userdata = WP_User::get_data_by( $field, $value );
    137138
    138139        if ( !$userdata )
    139140                return false;
    140141
     142        $key = $field . '|' . $value;
     143        if ( isset( $cache[$key] ) )
     144                return $cache[$key];
     145
    141146        $user = new WP_User;
    142147        $user->init( $userdata );
    143148
    144         return $user;
     149        $cache[$key] = $user;
     150        return $cache[$key];
    145151}
    146152endif;
    147153