From: Happy-melon Date: Thu, 6 Oct 2011 13:25:56 +0000 (+0000) Subject: FU r83909: restore preprocessing stage to cache link existence using LinkBatch; other... X-Git-Tag: 1.31.0-rc.0~27232 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=8155c0c477e889adea06ed9bed62c79a29ad4aa7;p=lhc%2Fweb%2Fwiklou.git FU r83909: restore preprocessing stage to cache link existence using LinkBatch; otherwise a separate DB query is done on every link. Since the ipb_by_text field is no longer in use we still have to do a cross-cast to get the usernames from the ids stored in ipb_by, but we can do that with one query via a UserArray, so it's not significantly worse than before. --- diff --git a/includes/specials/SpecialBlockList.php b/includes/specials/SpecialBlockList.php index 2a917c35d9..d40dd3cb41 100644 --- a/includes/specials/SpecialBlockList.php +++ b/includes/specials/SpecialBlockList.php @@ -200,6 +200,17 @@ class BlockListPager extends TablePager { protected $conds; protected $page; + /** + * Getting the user names from the userids stored in the ipb_by column can be + * expensive, so we cache the data here. + * @var Array of ID => Name + */ + private $userNameCache; + + /** + * @param $page SpecialPage + * @param $conds Array + */ function __construct( $page, $conds ) { $this->page = $page; $this->conds = $conds; @@ -241,7 +252,9 @@ class BlockListPager extends TablePager { $msg = array_combine( $msg, array_map( 'wfMessage', $msg ) ); } + /** @var $row object */ $row = $this->mCurrentRow; + $formatted = ''; switch( $name ) { @@ -300,11 +313,12 @@ class BlockListPager extends TablePager { break; case 'ipb_by': - $user = User::newFromId( $value ); - if( $user instanceof User ){ - $formatted = Linker::userLink( $user->getId(), $user->getName() ); - $formatted .= Linker::userToolLinks( $user->getId(), $user->getName() ); - } + $username = array_key_exists( $value, $this->userNameCache ) + ? $this->userNameCache[$value] + : User::newFromId( $value )->getName(); + + $formatted = Linker::userLink( $value, $username ); + $formatted .= Linker::userToolLinks( $value, $username ); break; case 'ipb_reason': @@ -389,4 +403,40 @@ class BlockListPager extends TablePager { function isFieldSortable( $name ) { return false; } + + /** + * Do a LinkBatch query to minimise database load when generating all these links + * @param $result + */ + function preprocessResults( $result ){ + wfProfileIn( __METHOD__ ); + # Do a link batch query + $lb = new LinkBatch; + $lb->setCaller( __METHOD__ ); + + $userids = array(); + + foreach ( $result as $row ) { + $userids[] = $row->ipb_by; + + # Usernames and titles are in fact related by a simple substitution of space -> underscore + # The last few lines of Title::secureAndSplit() tell the story. + $name = str_replace( ' ', '_', $row->ipb_address ); + $lb->add( NS_USER, $name ); + $lb->add( NS_USER_TALK, $name ); + } + + $ua = UserArray::newFromIDs( $userids ); + foreach( $ua as $user ){ + /* @var $user User */ + $this->userNameCache[$user->getID()] = $user->getName(); + + $name = str_replace( ' ', '_', $user->getName() ); + $lb->add( NS_USER, $name ); + $lb->add( NS_USER_TALK, $name ); + } + + $lb->execute(); + wfProfileOut( __METHOD__ ); + } }