r97270 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97269‎ | r97270 | r97271 >
Date:14:11, 16 September 2011
Author:nikerabbit
Status:deferred
Tags:
Comment:
Fixed two bugs in Stats code:
* Stats for subgroups of aggregate groups were not loaded -> those would be calculated again and inserted into database, which would fail with duplicate key
* Calculated stats was assigned into wrong place, which lead to duplicate calculation of stats for same group, again failing with db error
Modified paths:
  • /trunk/extensions/Translate/utils/MessageGroupStats.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/utils/MessageGroupStats.php
@@ -176,13 +176,26 @@
177177 return $stats;
178178 }
179179
 180+ protected static function expandAggregates( MessageGroup $group ) {
 181+ $flattened = array( $group->getId() );
 182+ if ( $group instanceof AggregateMessageGroup ) {
 183+ foreach ( $group->getGroups() as $subgroup ) {
 184+ $flattened = array_merge( $flattened, self::expandAggregates( $subgroup ) );
 185+ }
 186+ }
 187+ return $flattened;
 188+ }
 189+
 190+
 191+
180192 protected static function forGroupInternal( $group, $stats = array() ) {
181 - $id = $group->getId();
182 - $res = self::selectRowsIdLang( $id, null );
 193+ $ids = array_unique( self::expandAggregates( $group ) );
 194+ $res = self::selectRowsIdLang( $ids, null );
183195 $stats = self::extractResults( $res, $stats );
184196
185197 # Go over each language filling missing entries
186 - $languages = array_keys( Language::getLanguageNames() );
 198+ $id = $group->getId();
 199+ $languages = array_keys( Language::getLanguageNames( false ) );
187200 foreach ( $languages as $code ) {
188201 if ( isset( $stats[$id][$code] ) ) continue;
189202 $stats[$id][$code] = self::forItemInternal( $stats, $group, $code );
@@ -210,14 +223,9 @@
211224 $id = $group->getId();
212225
213226 if ( self::$timeStart !== null && ( microtime( true ) - self::$timeStart ) > self::$limit ) {
214 - return array( null, null, null );
 227+ return $stats[$id][$code] = array( null, null, null );
215228 }
216229
217 - // Might happen when called recursively
218 - if ( isset( $stats[$id][$code] ) ) {
219 - return $stats[$id][$code];
220 - }
221 -
222230 if ( $group instanceof AggregateMessageGroup ) {
223231 $aggregates = array( 0, 0, 0 );
224232 foreach ( $group->getGroups() as $sid => $sgroup ) {
@@ -226,7 +234,7 @@
227235 }
228236 $aggregates = self::multiAdd( $aggregates, $stats[$sid][$code] );
229237 }
230 - $stats[$id] = $aggregates;
 238+ $stats[$id][$code] = $aggregates;
231239 } else {
232240 $aggregates = self::calculateGroup( $group, $code );
233241 }

Status & tagging log