user: Move idFromName cache truncation to before adding the new value
authorAlexia E. Smith <washuu@gmail.com>
Fri, 14 Jun 2019 17:40:54 +0000 (12:40 -0500)
committerKrinkle <krinklemail@gmail.com>
Fri, 14 Jun 2019 18:05:26 +0000 (18:05 +0000)
This prevents a double query for the same User::idFromName() call
twice in a row.

Bug: T225843
Change-Id: I5beb0a3ad5e715b68dd8a450408fb089184fa6ce

includes/user/User.php

index e5dfceb..2de90ed 100644 (file)
@@ -950,12 +950,12 @@ class User implements IDBAccessObject, UserIdentity {
                        $result = (int)$s->user_id;
                }
 
-               self::$idCacheByName[$name] = $result;
-
-               if ( count( self::$idCacheByName ) > 1000 ) {
+               if ( count( self::$idCacheByName ) >= 1000 ) {
                        self::$idCacheByName = [];
                }
 
+               self::$idCacheByName[$name] = $result;
+
                return $result;
        }