r99100 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99099‎ | r99100 | r99101 >
Date:13:25, 6 October 2011
Author:happy-melon
Status:reverted (Comments)
Tags:lamecommitsummary 
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/specials/SpecialBlockList.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialBlockList.php
@@ -200,6 +200,17 @@
201201 protected $conds;
202202 protected $page;
203203
 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+ */
204215 function __construct( $page, $conds ) {
205216 $this->page = $page;
206217 $this->conds = $conds;
@@ -241,7 +252,9 @@
242253 $msg = array_combine( $msg, array_map( 'wfMessage', $msg ) );
243254 }
244255
 256+ /** @var $row object */
245257 $row = $this->mCurrentRow;
 258+
246259 $formatted = '';
247260
248261 switch( $name ) {
@@ -300,11 +313,12 @@
301314 break;
302315
303316 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 );
309323 break;
310324
311325 case 'ipb_reason':
@@ -389,4 +403,40 @@
390404 function isFieldSortable( $name ) {
391405 return false;
392406 }
 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+ }
393443 }

Sign-offs

UserFlagDate
Nikerabbitinspected17:14, 6 October 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r100254Join ipb_by to user table to get the user name. If we can't find a user, fall...aaron18:50, 19 October 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r83909Complete the trinity of blocking frontend interfaces by rewriting SpecialIpbl...happy-melon16:09, 14 March 2011

Comments

#Comment by Aaron Schulz (talk | contribs)   16:01, 6 October 2011

ipb_by_text is supposed to be used by centralauth crosswiki blocks.

#Comment by Happy-melon (talk | contribs)   20:44, 6 October 2011

I'm still working on that :D

#Comment by Aaron Schulz (talk | contribs)   22:49, 31 October 2011

Essentially reverted and redone in r99136.

#Comment by Happy-melon (talk | contribs)   23:53, 31 October 2011

Eh?

#Comment by Aaron Schulz (talk | contribs)   23:56, 31 October 2011

Should be r100254.

Status & tagging log