r113696 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113695‎ | r113696 | r113697 >
Date:00:32, 13 March 2012
Author:aaron
Status:ok (Comments)
Tags:
Comment:
(bug 34978) Use a rev parent batch query to get the diff sizes for history pages rather than rely on assumptions that break if any filtering is used.
Modified paths:
  • /trunk/phase3/includes/actions/HistoryAction.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/actions/HistoryAction.php
@@ -316,6 +316,10 @@
317317 public $lastRow = false, $counter, $historyPage, $buttons, $conds;
318318 protected $oldIdChecked;
319319 protected $preventClickjacking = false;
 320+ /**
 321+ * @var array
 322+ */
 323+ protected $parentLens;
320324
321325 function __construct( $historyPage, $year = '', $month = '', $tagFilter = '', $conds = array() ) {
322326 parent::__construct( $historyPage->getContext() );
@@ -384,7 +388,11 @@
385389 # Do a link batch query
386390 $this->mResult->seek( 0 );
387391 $batch = new LinkBatch();
 392+ $revIds = array();
388393 foreach ( $this->mResult as $row ) {
 394+ if( $row->rev_parent_id ) {
 395+ $revIds[] = $row->rev_parent_id;
 396+ }
389397 if( !is_null( $row->user_name ) ) {
390398 $batch->add( NS_USER, $row->user_name );
391399 $batch->add( NS_USER_TALK, $row->user_name );
@@ -393,11 +401,35 @@
394402 $batch->add( NS_USER_TALK, $row->rev_user_text );
395403 }
396404 }
 405+ $this->parentLens = $this->getParentLengths( $revIds );
397406 $batch->execute();
398407 $this->mResult->seek( 0 );
399408 }
400409
401410 /**
 411+ * Do a batched query to get the parent revision lengths
 412+ * @param $revIds array
 413+ * @return array
 414+ * @TODO: stolen from Contributions, refactor
 415+ */
 416+ private function getParentLengths( array $revIds ) {
 417+ $revLens = array();
 418+ if ( !$revIds ) {
 419+ return $revLens; // empty
 420+ }
 421+ wfProfileIn( __METHOD__ );
 422+ $res = $this->mDb->select( 'revision',
 423+ array( 'rev_id', 'rev_len' ),
 424+ array( 'rev_id' => $revIds ),
 425+ __METHOD__ );
 426+ foreach ( $res as $row ) {
 427+ $revLens[$row->rev_id] = $row->rev_len;
 428+ }
 429+ wfProfileOut( __METHOD__ );
 430+ return $revLens;
 431+ }
 432+
 433+ /**
402434 * Creates begin of history list with a submit button
403435 *
404436 * @return string HTML output
@@ -574,7 +606,9 @@
575607 }
576608
577609 # Size is always public data
578 - $prevSize = $prevRev ? $prevRev->getSize() : 0;
 610+ $prevSize = isset( $this->parentLens[$row->rev_parent_id] )
 611+ ? $this->parentLens[$row->rev_parent_id]
 612+ : 0;
579613 $sDiff = ChangesList::showCharacterDifference( $prevSize, $rev->getSize() );
580614 $fSize = Linker::formatRevisionSize($rev->getSize());
581615 $s .= " . . $fSize $sDiff . . ";

Comments

#Comment by Platonides (talk | contribs)   21:19, 16 March 2012

Use parentLengths instead of parentLens?

Status & tagging log