From 25aee49ca510a4b209130d8e39d6d3f614a6ad7b Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 21 Sep 2011 13:17:10 +0100 Subject: [PATCH 1/3] [ticket/10375] Use existing method to generate cache file name. PHPBB3-10375 --- phpBB/includes/template/template.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 0495ade9c5..d1aa67038c 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -307,10 +307,9 @@ class phpbb_template */ private function _tpl_load($handle) { - $virtual_source_file = $this->locator->get_virtual_source_file_for_handle($handle); $source_file = null; - $compiled_path = $this->cachepath . str_replace('/', '.', $virtual_source_file) . '.' . $this->phpEx; + $compiled_path = $this->_compiled_file_for_handle($handle); $recompile = defined('DEBUG_EXTRA') || !file_exists($compiled_path) || From 9d5e9af54b2bf45baa3faa6195c2c185c08a0d4e Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 21 Sep 2011 13:17:51 +0100 Subject: [PATCH 2/3] [ticket/10375] Make _tpl_load() a little leaner. - Removed duplicate variables - Set $source_file earlier for cache checks - Fixed useless mtime check PHPBB3-10375 --- phpBB/includes/template/template.php | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index d1aa67038c..e8220b25bf 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -307,35 +307,22 @@ class phpbb_template */ private function _tpl_load($handle) { - $source_file = null; - - $compiled_path = $this->_compiled_file_for_handle($handle); + $source_file = $this->locator->get_source_file_for_handle($handle); + $output_file = $this->_compiled_file_for_handle($handle); $recompile = defined('DEBUG_EXTRA') || - !file_exists($compiled_path) || - @filesize($compiled_path) === 0 || - ($this->config['load_tplcompile'] && @filemtime($compiled_path) < @filemtime($source_file)); - - if (!$recompile && $this->config['load_tplcompile']) - { - $source_file = $this->locator->get_source_file_for_handle($handle); - $recompile = (@filemtime($compiled_path) < @filemtime($source_file)) ? true : false; - } + !file_exists($output_file) || + @filesize($output_file) === 0 || + ($this->config['load_tplcompile'] && @filemtime($output_file) < @filemtime($source_file)); // Recompile page if the original template is newer, otherwise load the compiled version if (!$recompile) { - return new phpbb_template_renderer_include($compiled_path, $this); - } - - if ($source_file === null) - { - $source_file = $this->locator->get_source_file_for_handle($handle); + return new phpbb_template_renderer_include($output_file, $this); } $compile = new phpbb_template_compile($this->config['tpl_allow_php']); - $output_file = $this->_compiled_file_for_handle($handle); if ($compile->compile_file_to_file($source_file, $output_file) !== false) { $renderer = new phpbb_template_renderer_include($output_file, $this); From 95d24e6fb7389adfeaa46e97a49b1c15b5a740ca Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 21 Sep 2011 13:24:04 +0100 Subject: [PATCH 3/3] [ticket/10375] Rework $source_file setting. Only set the file if an mtime check or recompile are required. PHPBB3-10375 --- phpBB/includes/template/template.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index e8220b25bf..ec5fbe2829 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -307,13 +307,22 @@ class phpbb_template */ private function _tpl_load($handle) { - $source_file = $this->locator->get_source_file_for_handle($handle); $output_file = $this->_compiled_file_for_handle($handle); $recompile = defined('DEBUG_EXTRA') || !file_exists($output_file) || - @filesize($output_file) === 0 || - ($this->config['load_tplcompile'] && @filemtime($output_file) < @filemtime($source_file)); + @filesize($output_file) === 0; + + if ($recompile || $this->config['load_tplcompile']) + { + // Set only if a recompile or an mtime check are required. + $source_file = $this->locator->get_source_file_for_handle($handle); + + if (!$recompile && @filemtime($output_file) < @filemtime($source_file)) + { + $recompile = true; + } + } // Recompile page if the original template is newer, otherwise load the compiled version if (!$recompile)