r73303 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73302‎ | r73303 | r73304 >
Date:07:26, 19 September 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Quick bandage for too slow Special:LangugeStats
Modified paths:
  • /trunk/extensions/Translate/Groups.php (modified) (history)
  • /trunk/extensions/Translate/SpecialLanguageStats.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/SpecialLanguageStats.php
@@ -216,33 +216,17 @@
217217
218218 $fuzzy = $translated = $total = 0;
219219
220 - $incache = $cache->get( $groupName, $code );
221 - if ( $incache !== false ) {
222 - list( $fuzzy, $translated, $total ) = $incache;
 220+ if ( $g instanceof AggregateMessageGroup ) {
 221+ foreach ( $g->getGroups() as $subgroup ) {
 222+ $result = $this->loadPercentages( $cache, $subgroup, $code );
 223+ $fuzzy += $result[0];
 224+ $translated += $result[1];
 225+ $total += $result[2];
 226+ }
 227+ } else {
 228+ list( $fuzzy, $translated, $total ) = $this->loadPercentages( $cache, $g, $code );
223229 }
224230
225 - // Re-calculate if cache is empty or insane
226 - if ( !$total ) {
227 - // Initialise messages.
228 - $collection = $g->initCollection( $code );
229 - $collection->setInFile( $g->load( $code ) );
230 - $collection->filter( 'ignored' );
231 - $collection->filter( 'optional' );
232 - // Store the count of real messages for later calculation.
233 - $total = count( $collection );
234 -
235 - // Count fuzzy first.
236 - $collection->filter( 'fuzzy' );
237 - $fuzzy = $total - count( $collection );
238 -
239 - // Count the completed translations.
240 - $collection->filter( 'hastranslation', false );
241 - $translated = count( $collection );
242 -
243 - $cache->set( $groupName, $code, array( $fuzzy, $translated, $total ) );
244 - $cache->commit();
245 - }
246 -
247231 if ( $total === 0 ) {
248232 wfWarn( __METHOD__ . ": Group $groupName has zero message ($code)" );
249233 continue;
@@ -291,6 +275,38 @@
292276 return $out;
293277 }
294278
 279+ protected function loadPercentages( $cache, $group, $code ) {
 280+ $incache = $cache->get( $group->getId(), $code );
 281+ if ( $incache !== false ) {
 282+ return $incache;
 283+ }
 284+
 285+ // Initialise messages.
 286+ $collection = $group->initCollection( $code );
 287+ $collection->setInFile( $group->load( $code ) );
 288+ $collection->filter( 'ignored' );
 289+ $collection->filter( 'optional' );
 290+ // Store the count of real messages for later calculation.
 291+ $total = count( $collection );
 292+
 293+ // Count fuzzy first.
 294+ $collection->filter( 'fuzzy' );
 295+ $fuzzy = $total - count( $collection );
 296+
 297+ // Count the completed translations.
 298+ $collection->filter( 'hastranslation', false );
 299+ $translated = count( $collection );
 300+
 301+ $result = array( $fuzzy, $translated, $total );
 302+
 303+ $cache->set( $group->getId(), $code, $result );
 304+
 305+ static $i = 0;
 306+ if ( $i++ % 50 === 0 ) $cache->commit();
 307+
 308+ return $result;
 309+ }
 310+
295311 protected function formatPercentage( $num ) {
296312 global $wgLang;
297313 $fmt = $wgLang->formatNum( number_format( round( 100 * $num, 2 ), 2 ) );
Index: trunk/extensions/Translate/Groups.php
@@ -502,7 +502,7 @@
503503 return $this->mangler;
504504 }
505505
506 - protected function getGroups() {
 506+ public function getGroups() {
507507 if ( !isset( $this->groups ) ) {
508508 $groups = array();
509509 $ids = (array) $this->conf['GROUPS'];

Status & tagging log