From: Aaron Schulz Date: Tue, 13 Mar 2012 00:32:47 +0000 (+0000) Subject: (bug 34978) Use a rev parent batch query to get the diff sizes for history pages... X-Git-Tag: 1.31.0-rc.0~24280 X-Git-Url: http://git.cyclocoop.org///%22%40url%40//%22?a=commitdiff_plain;h=d7adc3c373c5457660e0154a73282c3e552560c3;p=lhc%2Fweb%2Fwiklou.git (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. --- diff --git a/includes/actions/HistoryAction.php b/includes/actions/HistoryAction.php index c5b865211f..dbc1ac07b8 100644 --- a/includes/actions/HistoryAction.php +++ b/includes/actions/HistoryAction.php @@ -316,6 +316,10 @@ class HistoryPager extends ReverseChronologicalPager { public $lastRow = false, $counter, $historyPage, $buttons, $conds; protected $oldIdChecked; protected $preventClickjacking = false; + /** + * @var array + */ + protected $parentLens; function __construct( $historyPage, $year = '', $month = '', $tagFilter = '', $conds = array() ) { parent::__construct( $historyPage->getContext() ); @@ -384,7 +388,11 @@ class HistoryPager extends ReverseChronologicalPager { # Do a link batch query $this->mResult->seek( 0 ); $batch = new LinkBatch(); + $revIds = array(); foreach ( $this->mResult as $row ) { + if( $row->rev_parent_id ) { + $revIds[] = $row->rev_parent_id; + } if( !is_null( $row->user_name ) ) { $batch->add( NS_USER, $row->user_name ); $batch->add( NS_USER_TALK, $row->user_name ); @@ -393,10 +401,34 @@ class HistoryPager extends ReverseChronologicalPager { $batch->add( NS_USER_TALK, $row->rev_user_text ); } } + $this->parentLens = $this->getParentLengths( $revIds ); $batch->execute(); $this->mResult->seek( 0 ); } + /** + * Do a batched query to get the parent revision lengths + * @param $revIds array + * @return array + * @TODO: stolen from Contributions, refactor + */ + private function getParentLengths( array $revIds ) { + $revLens = array(); + if ( !$revIds ) { + return $revLens; // empty + } + wfProfileIn( __METHOD__ ); + $res = $this->mDb->select( 'revision', + array( 'rev_id', 'rev_len' ), + array( 'rev_id' => $revIds ), + __METHOD__ ); + foreach ( $res as $row ) { + $revLens[$row->rev_id] = $row->rev_len; + } + wfProfileOut( __METHOD__ ); + return $revLens; + } + /** * Creates begin of history list with a submit button * @@ -574,7 +606,9 @@ class HistoryPager extends ReverseChronologicalPager { } # Size is always public data - $prevSize = $prevRev ? $prevRev->getSize() : 0; + $prevSize = isset( $this->parentLens[$row->rev_parent_id] ) + ? $this->parentLens[$row->rev_parent_id] + : 0; $sDiff = ChangesList::showCharacterDifference( $prevSize, $rev->getSize() ); $fSize = Linker::formatRevisionSize($rev->getSize()); $s .= " . . $fSize $sDiff . . ";