From 758cb94e01945b16f730c08775666d3f5e65eb86 Mon Sep 17 00:00:00 2001 From: czaks Date: Sun, 5 Apr 2015 16:52:35 +0200 Subject: [PATCH] optimization: locale caching, so we don`t have to reparse instance-config every single time --- inc/functions.php | 26 ++++++++++++++++++-------- 1 file 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) {