From: Andrew Garrett Date: Fri, 26 Jun 2009 14:28:25 +0000 (+0000) Subject: Add in-process caching to User::idFromName X-Git-Tag: 1.31.0-rc.0~41202 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=eb731b3514de0bc7310a32891cda5a139d063bb6;p=lhc%2Fweb%2Fwiklou.git Add in-process caching to User::idFromName --- diff --git a/includes/User.php b/includes/User.php index 5849ec0b12..689c580263 100644 --- a/includes/User.php +++ b/includes/User.php @@ -456,14 +456,29 @@ class User { # Illegal name return null; } + + static $cache = array(); + + if ( isset($cache[$name]) ) { + return $cache[$name]; + } + $dbr = wfGetDB( DB_SLAVE ); $s = $dbr->selectRow( 'user', array( 'user_id' ), array( 'user_name' => $nt->getText() ), __METHOD__ ); if ( $s === false ) { - return 0; + $result = 0; } else { - return $s->user_id; + $result = $s->user_id; } + + $cache[$name] = $result; + + if ( count($cache) > 1000 ) { + $cache = array(); + } + + return $result; } /**