mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-11-28 18:20:06 +00:00
Merge "Make the maximum language cache size configurable"
This commit is contained in:
commit
ad76e92f76
|
@ -168,6 +168,13 @@ $wgScribuntoEngineConf = array(
|
|||
// implemented in the future, and there is no guarantee that a
|
||||
// simulation of setfenv() and getfenv() will be provided.
|
||||
'allowEnvFuncs' => false,
|
||||
|
||||
// The maximum number of languages about which data can be requested.
|
||||
// The cost is about 1.5MB of memory usage per language on default
|
||||
// installations (during recache), but if recaching is disabled with
|
||||
// $wgLocalisationCacheConf['manualRecache'] = false
|
||||
// then memory usage is perhaps 10x smaller.
|
||||
'maxLangCacheSize' => 30,
|
||||
),
|
||||
'luastandalone' => array(
|
||||
'class' => 'Scribunto_LuaStandaloneEngine',
|
||||
|
@ -182,6 +189,7 @@ $wgScribuntoEngineConf = array(
|
|||
'memoryLimit' => 50 * 1024 * 1024,
|
||||
'cpuLimit' => 7,
|
||||
'allowEnvFuncs' => false,
|
||||
'maxLangCacheSize' => 30,
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
@ -122,6 +122,17 @@ abstract class ScribuntoEngineBase {
|
|||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an element from the configuration array
|
||||
*
|
||||
* @param string $optionName
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOption( $optionName ) {
|
||||
return isset( $this->options[$optionName] )
|
||||
? $this->options[$optionName] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message
|
||||
* @param $params array
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
|
||||
// @codingStandardsIgnoreLine Squiz.Classes.ValidClassName.NotCamelCaps
|
||||
class Scribunto_LuaLanguageLibrary extends Scribunto_LuaLibraryBase {
|
||||
const MAX_LANG_CACHE_SIZE = 20;
|
||||
|
||||
public $langCache = array();
|
||||
public $timeCache = array();
|
||||
public $maxLangCacheSize;
|
||||
|
||||
function register() {
|
||||
// Pre-populate the language cache
|
||||
global $wgContLang;
|
||||
$this->langCache[$wgContLang->getCode()] = $wgContLang;
|
||||
$this->maxLangCacheSize = $this->getEngine()->getOption( 'maxLangCacheSize' );
|
||||
|
||||
$statics = array(
|
||||
'getContLangCode',
|
||||
|
@ -111,7 +111,7 @@ class Scribunto_LuaLanguageLibrary extends Scribunto_LuaLibraryBase {
|
|||
$name = strval( $name );
|
||||
$code = array_shift( $args );
|
||||
if ( !isset( $this->langCache[$code] ) ) {
|
||||
if ( count( $this->langCache ) > self::MAX_LANG_CACHE_SIZE ) {
|
||||
if ( count( $this->langCache ) > $this->maxLangCacheSize ) {
|
||||
throw new Scribunto_LuaError( 'too many language codes requested' );
|
||||
}
|
||||
try {
|
||||
|
|
|
@ -16,6 +16,7 @@ abstract class Scribunto_LuaEngineTestBase extends MediaWikiLangTestCase {
|
|||
'memoryLimit' => 50000000,
|
||||
'cpuLimit' => 30,
|
||||
'allowEnvFuncs' => true,
|
||||
'maxLangCacheSize' => 30,
|
||||
),
|
||||
'LuaStandalone' => array(
|
||||
'errorFile' => null,
|
||||
|
@ -23,6 +24,7 @@ abstract class Scribunto_LuaEngineTestBase extends MediaWikiLangTestCase {
|
|||
'memoryLimit' => 50000000,
|
||||
'cpuLimit' => 30,
|
||||
'allowEnvFuncs' => true,
|
||||
'maxLangCacheSize' => 30,
|
||||
),
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in a new issue