Make UserCache only look up a user once.
authorBrian Wolff <bawolff+wn@gmail.com>
Wed, 17 Apr 2013 21:23:11 +0000 (18:23 -0300)
committerBrian Wolff <bawolff+wn@gmail.com>
Wed, 17 Apr 2013 21:28:05 +0000 (18:28 -0300)
I noticed on special:listfiles/username, UserCache was doing queries
like select user_whatever from user where user_id in ( '1', '1', ...)
with the same user id 50 times (one for each result returned in the
special page). That seemed a little insane, so put the list of
users to query through a array_unique. (Quite likely the db would
optimize that query to not literally look up the same user 50 times,
but nonetheless it seems better to filter the list before then)

Change-Id: I80c8a359d0f7a53b2420ebcda641e594dd3c56e9

includes/cache/UserCache.php

index 694c1a1..63d4141 100644 (file)
@@ -81,6 +81,8 @@ class UserCache {
                $usersToCheck = array();
                $usersToQuery = array();
 
+               $userIds = array_unique( $userIds );
+
                foreach ( $userIds as $userId ) {
                        $userId = (int)$userId;
                        if ( $userId <= 0 ) {