diff options
| author | czaks <marcin@6irc.net> | 2015-04-05 16:52:35 +0200 |
|---|---|---|
| committer | czaks <marcin@6irc.net> | 2015-04-05 16:52:35 +0200 |
| commit | 758cb94e01945b16f730c08775666d3f5e65eb86 (patch) | |
| tree | 68861bea384cacac60caf5fd56d10035b88aed47 /inc | |
| parent | e997357084fb9630e6c5098a912b6122aa0f2b56 (diff) | |
optimization: locale caching, so we don`t have to reparse instance-config every single time
Diffstat (limited to 'inc')
| -rwxr-xr-x | inc/functions.php | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/inc/functions.php b/inc/functions.php index 8a98659b..fc22e6ce 100755 --- a/inc/functions.php +++ b/inc/functions.php @@ -96,18 +96,28 @@ function loadConfig() { // Initialize locale as early as possible - $config['locale'] = 'en'; + // Those calls are expensive. Unfortunately, our cache system is not initialized at this point. + // So, we may store the locale in a tmp/ filesystem. - $configstr = file_get_contents('inc/instance-config.php'); + if (file_exists($fn = 'tmp/cache/locale_' . ( isset($board['uri']) ? $board['uri'] : '' ) ) ) { + $config['locale'] = file_get_contents($fn); + } + else { + $config['locale'] = 'en'; + + $configstr = file_get_contents('inc/instance-config.php'); if (isset($board['dir']) && file_exists($board['dir'] . '/config.php')) { - $configstr .= file_get_contents($board['dir'] . '/config.php'); + $configstr .= file_get_contents($board['dir'] . '/config.php'); } - $matches = array(); - preg_match_all('/[^\/*#]\$config\s*\[\s*[\'"]locale[\'"]\s*\]\s*=\s*([\'"])(.*?)\1/', $configstr, $matches); - if ($matches && isset ($matches[2]) && $matches[2]) { - $matches = $matches[2]; - $config['locale'] = $matches[count($matches)-1]; + $matches = array(); + preg_match_all('/[^\/*#]\$config\s*\[\s*[\'"]locale[\'"]\s*\]\s*=\s*([\'"])(.*?)\1/', $configstr, $matches); + if ($matches && isset ($matches[2]) && $matches[2]) { + $matches = $matches[2]; + $config['locale'] = $matches[count($matches)-1]; + } + + file_put_contents($fn, $config['locale']); } if ($config['locale'] != $current_locale) { |
