Index: trunk/phase3/includes/specials/SpecialBlockList.php |
— | — | @@ -200,6 +200,17 @@ |
201 | 201 | protected $conds; |
202 | 202 | protected $page; |
203 | 203 | |
| 204 | + /** |
| 205 | + * Getting the user names from the userids stored in the ipb_by column can be |
| 206 | + * expensive, so we cache the data here. |
| 207 | + * @var Array of ID => Name |
| 208 | + */ |
| 209 | + private $userNameCache; |
| 210 | + |
| 211 | + /** |
| 212 | + * @param $page SpecialPage |
| 213 | + * @param $conds Array |
| 214 | + */ |
204 | 215 | function __construct( $page, $conds ) { |
205 | 216 | $this->page = $page; |
206 | 217 | $this->conds = $conds; |
— | — | @@ -241,7 +252,9 @@ |
242 | 253 | $msg = array_combine( $msg, array_map( 'wfMessage', $msg ) ); |
243 | 254 | } |
244 | 255 | |
| 256 | + /** @var $row object */ |
245 | 257 | $row = $this->mCurrentRow; |
| 258 | + |
246 | 259 | $formatted = ''; |
247 | 260 | |
248 | 261 | switch( $name ) { |
— | — | @@ -300,11 +313,12 @@ |
301 | 314 | break; |
302 | 315 | |
303 | 316 | case 'ipb_by': |
304 | | - $user = User::newFromId( $value ); |
305 | | - if( $user instanceof User ){ |
306 | | - $formatted = Linker::userLink( $user->getId(), $user->getName() ); |
307 | | - $formatted .= Linker::userToolLinks( $user->getId(), $user->getName() ); |
308 | | - } |
| 317 | + $username = array_key_exists( $value, $this->userNameCache ) |
| 318 | + ? $this->userNameCache[$value] |
| 319 | + : User::newFromId( $value )->getName(); |
| 320 | + |
| 321 | + $formatted = Linker::userLink( $value, $username ); |
| 322 | + $formatted .= Linker::userToolLinks( $value, $username ); |
309 | 323 | break; |
310 | 324 | |
311 | 325 | case 'ipb_reason': |
— | — | @@ -389,4 +403,40 @@ |
390 | 404 | function isFieldSortable( $name ) { |
391 | 405 | return false; |
392 | 406 | } |
| 407 | + |
| 408 | + /** |
| 409 | + * Do a LinkBatch query to minimise database load when generating all these links |
| 410 | + * @param $result |
| 411 | + */ |
| 412 | + function preprocessResults( $result ){ |
| 413 | + wfProfileIn( __METHOD__ ); |
| 414 | + # Do a link batch query |
| 415 | + $lb = new LinkBatch; |
| 416 | + $lb->setCaller( __METHOD__ ); |
| 417 | + |
| 418 | + $userids = array(); |
| 419 | + |
| 420 | + foreach ( $result as $row ) { |
| 421 | + $userids[] = $row->ipb_by; |
| 422 | + |
| 423 | + # Usernames and titles are in fact related by a simple substitution of space -> underscore |
| 424 | + # The last few lines of Title::secureAndSplit() tell the story. |
| 425 | + $name = str_replace( ' ', '_', $row->ipb_address ); |
| 426 | + $lb->add( NS_USER, $name ); |
| 427 | + $lb->add( NS_USER_TALK, $name ); |
| 428 | + } |
| 429 | + |
| 430 | + $ua = UserArray::newFromIDs( $userids ); |
| 431 | + foreach( $ua as $user ){ |
| 432 | + /* @var $user User */ |
| 433 | + $this->userNameCache[$user->getID()] = $user->getName(); |
| 434 | + |
| 435 | + $name = str_replace( ' ', '_', $user->getName() ); |
| 436 | + $lb->add( NS_USER, $name ); |
| 437 | + $lb->add( NS_USER_TALK, $name ); |
| 438 | + } |
| 439 | + |
| 440 | + $lb->execute(); |
| 441 | + wfProfileOut( __METHOD__ ); |
| 442 | + } |
393 | 443 | } |