r50419 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50418‎ | r50419 | r50420 >
Date:09:11, 10 May 2009
Author:nikerabbit
Status:ok
Tags:
Comment:
* Use memcached instead to avoid permission problems, and the size of this data is not very big
Modified paths:
  • /trunk/extensions/Translate/utils/MessageIndex.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/utils/MessageIndex.php
@@ -60,9 +60,11 @@
6161 self::checkAndAdd( $hugearray, $g, true );
6262 }
6363
 64+ global $wgMemc;
6465 foreach ( $hugearray as $ns => $array ) {
65 - wfMkdirParents( dirname( self::file($ns) ) );
66 - file_put_contents( self::file($ns), serialize( $array ) );
 66+ $memcKey = wfMemcKey( 'messageindex', $ns );
 67+ $wgMemc->set( $memcKey, serialize( $array ), 60*60*12 );
 68+ $cache = $wgMemc->get( $memcKey );
6769 }
6870 }
6971
@@ -92,32 +94,22 @@
9395
9496 }
9597
96 - protected static function file( $namespace ) {
97 - $dir = realpath( dirname( __FILE__ ) . '/../data' );
98 - $namepace = MWNamespace::getCanonicalName( $namespace );
99 - return "$dir/messageindex-$namespace.ser";
100 - }
101 -
10298 protected static function normaliseKey( $key ) {
103 - return str_replace( " ", "_", strtolower( $key ) );
 99+ global $wgContLang;
 100+ return $wgContLang->ucfirst( str_replace( " ", "_", $key ) );
104101 }
105102
106103 protected static function index( $namespace ) {
107 - if ( !isset(self::$cache[$namespace]) ) {
 104+ global $wgMemc;
 105+ $memcKey = wfMemcKey( 'messageindex', $namespace );
 106+ $cache = unserialize( $wgMemc->get($memcKey) );
108107
109 - $file = self::file( $namespace );
110 - if ( !file_exists( $file ) ) {
111 - self::cache( $namespace );
112 - }
 108+ // Missing? Update it
 109+ if ( !is_array($cache) ) self::cache( $namespace );
 110+ $cache = unserialize( $wgMemc->get($memcKey) );
 111+ if ( !is_array($cache) ) throw new MWException( "Caching failed" );
113112
114 - if ( file_exists( $file ) ) {
115 - self::$cache[$namespace] = unserialize( file_get_contents( $file ) );
116 - } else {
117 - self::$cache[$namespace] = array();
118 - wfDebug( __METHOD__ . ": Message index missing." );
119 - }
120 - }
 113+ return $cache;
121114
122 - return self::$cache[$namespace];
123115 }
124116 }
\ No newline at end of file

Status & tagging log