http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73303

Revision: 73303
Author:   nikerabbit
Date:     2010-09-19 07:26:29 +0000 (Sun, 19 Sep 2010)

Log Message:
-----------
Quick bandage for too slow Special:LangugeStats

Modified Paths:
--------------
    trunk/extensions/Translate/Groups.php
    trunk/extensions/Translate/SpecialLanguageStats.php

Modified: trunk/extensions/Translate/Groups.php
===================================================================
--- trunk/extensions/Translate/Groups.php       2010-09-19 04:38:08 UTC (rev 
73302)
+++ trunk/extensions/Translate/Groups.php       2010-09-19 07:26:29 UTC (rev 
73303)
@@ -502,7 +502,7 @@
                return $this->mangler;
        }
 
-       protected function getGroups() {
+       public function getGroups() {
                if ( !isset( $this->groups ) ) {
                        $groups = array();
                        $ids = (array) $this->conf['GROUPS'];

Modified: trunk/extensions/Translate/SpecialLanguageStats.php
===================================================================
--- trunk/extensions/Translate/SpecialLanguageStats.php 2010-09-19 04:38:08 UTC 
(rev 73302)
+++ trunk/extensions/Translate/SpecialLanguageStats.php 2010-09-19 07:26:29 UTC 
(rev 73303)
@@ -216,33 +216,17 @@
 
                        $fuzzy = $translated = $total = 0;
 
-                       $incache = $cache->get( $groupName, $code );
-                       if ( $incache !== false ) {
-                               list( $fuzzy, $translated, $total ) = $incache;
+                       if ( $g instanceof AggregateMessageGroup ) {
+                               foreach ( $g->getGroups() as $subgroup ) {
+                                       $result = $this->loadPercentages( 
$cache, $subgroup, $code );
+                                       $fuzzy += $result[0];
+                                       $translated += $result[1];
+                                       $total += $result[2];
+                               }
+                       } else {
+                               list( $fuzzy, $translated, $total ) = 
$this->loadPercentages( $cache, $g, $code );
                        }
 
-                       // Re-calculate if cache is empty or insane
-                       if ( !$total ) {
-                               // Initialise messages.
-                               $collection = $g->initCollection( $code );
-                               $collection->setInFile( $g->load( $code ) );
-                               $collection->filter( 'ignored' );
-                               $collection->filter( 'optional' );
-                               // Store the count of real messages for later 
calculation.
-                               $total = count( $collection );
-
-                               // Count fuzzy first.
-                               $collection->filter( 'fuzzy' );
-                               $fuzzy = $total - count( $collection );
-
-                               // Count the completed translations.
-                               $collection->filter( 'hastranslation', false );
-                               $translated = count( $collection );
-
-                               $cache->set( $groupName, $code, array( $fuzzy, 
$translated, $total ) );
-                               $cache->commit();
-                       }
-
                        if ( $total === 0 ) {
                                wfWarn( __METHOD__ . ": Group $groupName has 
zero message ($code)" );
                                continue;
@@ -291,6 +275,38 @@
                return $out;
        }
 
+       protected function loadPercentages( $cache, $group, $code ) {
+               $incache = $cache->get( $group->getId(), $code );
+               if ( $incache !== false ) {
+                       return $incache;
+               }
+
+               // Initialise messages.
+               $collection = $group->initCollection( $code );
+               $collection->setInFile( $group->load( $code ) );
+               $collection->filter( 'ignored' );
+               $collection->filter( 'optional' );
+               // Store the count of real messages for later calculation.
+               $total = count( $collection );
+
+               // Count fuzzy first.
+               $collection->filter( 'fuzzy' );
+               $fuzzy = $total - count( $collection );
+
+               // Count the completed translations.
+               $collection->filter( 'hastranslation', false );
+               $translated = count( $collection );
+
+               $result = array( $fuzzy, $translated, $total );
+
+               $cache->set( $group->getId(), $code, $result );
+
+               static $i = 0;
+               if ( $i++ % 50 === 0 ) $cache->commit();
+
+               return $result;
+       }
+
        protected function formatPercentage( $num ) {
                global $wgLang;
                $fmt = $wgLang->formatNum( number_format( round( 100 * $num, 2 
), 2 ) );



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to