From efaa61cfb6c694c2b026de24c60636c718c053e6 Mon Sep 17 00:00:00 2001 From: uwetews Date: Mon, 21 Dec 2015 02:18:27 +0100 Subject: [PATCH] - optimization improve speed of filetime checks on extends and extendsall resource --- change_log.txt | 3 +++ demo/plugins/resource.extendsall.php | 27 +++++++++++-------- libs/Smarty.class.php | 2 +- .../smarty_internal_resource_extends.php | 13 ++++++++- ...arty_internal_runtime_validatecompiled.php | 9 +++++-- libs/sysplugins/smarty_resource.php | 10 +++++++ 6 files changed, 49 insertions(+), 15 deletions(-) diff --git a/change_log.txt b/change_log.txt index daaefb28..34117478 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@  ===== 3.1.29-dev ===== (xx.xx.2015) + 21.12.2015 + - optimization improve speed of filetime checks on extends and extendsall resource + 20.12.2015 - bugfix failure when the default resource type was set to 'extendsall' https://github.com/smarty-php/smarty/issues/123 - update compilation of Smarty special variables diff --git a/demo/plugins/resource.extendsall.php b/demo/plugins/resource.extendsall.php index a6dd5e48..5f55d44b 100644 --- a/demo/plugins/resource.extendsall.php +++ b/demo/plugins/resource.extendsall.php @@ -22,7 +22,7 @@ class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends { $uid = ''; $sources = array(); - $exists = true; + $timestamp = 0; foreach ($_template->smarty->getTemplateDir() as $key => $directory) { try { $s = Smarty_Resource::source(null, $source->smarty, 'file:' . '[' . $key . ']' . $source->name); @@ -31,30 +31,35 @@ class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends } $sources[ $s->uid ] = $s; $uid .= $s->filepath; + $timestamp = $s->timestamp > $timestamp ? $s->timestamp : $timestamp; } catch (SmartyException $e) { } } - if (!$sources) { $source->exists = false; - $source->template = $_template; - return; } $sources = array_reverse($sources, true); reset($sources); $s = current($sources); - $source->components = $sources; $source->filepath = $s->filepath; $source->uid = sha1($uid . $_template->smarty->_joined_template_dir); - $source->exists = $exists; - if ($_template && $_template->smarty->compile_check) { - $source->timestamp = $s->timestamp; - } - // need the template at getContent() - $source->template = $_template; + $source->exists = true; + $source->timestamp = $timestamp; } + + /* + * Disable timestamp checks for extendsall resource. + * The individual source components will be checked. + * + * @return bool + */ + public function checkTimestamps() + { + return false; + } + } diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 4acffc75..549e4566 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -118,7 +118,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.29-dev/17'; + const SMARTY_VERSION = '3.1.29-dev/18'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_internal_resource_extends.php b/libs/sysplugins/smarty_internal_resource_extends.php index 0c0802d6..3d687dca 100644 --- a/libs/sysplugins/smarty_internal_resource_extends.php +++ b/libs/sysplugins/smarty_internal_resource_extends.php @@ -44,7 +44,7 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource if ($_s->type == 'php') { throw new SmartyException("Resource type {$_s->type} cannot be used with the extends resource type"); } - $sources[$_s->uid] = $_s; + $sources[ $_s->uid ] = $_s; $uid .= $_s->filepath; if ($_template) { $exists = $exists && $_s->exists; @@ -110,4 +110,15 @@ class Smarty_Internal_Resource_Extends extends Smarty_Resource { return str_replace(':', '.', basename($source->filepath)); } + + /* + * Disable timestamp checks for extends resource. + * The individual source components will be checked. + * + * @return bool + */ + public function checkTimestamps() + { + return false; + } } diff --git a/libs/sysplugins/smarty_internal_runtime_validatecompiled.php b/libs/sysplugins/smarty_internal_runtime_validatecompiled.php index 402a08f4..7defd6c9 100644 --- a/libs/sysplugins/smarty_internal_runtime_validatecompiled.php +++ b/libs/sysplugins/smarty_internal_runtime_validatecompiled.php @@ -43,8 +43,13 @@ class Smarty_Internal_Runtime_ValidateCompiled } elseif ($_file_to_check[2] == 'string') { continue; } else { - $source = Smarty_Template_Source::load($tpl, $tpl->smarty, $_file_to_check[0]); - $mtime = $source->getTimeStamp(); + $handler = Smarty_Resource::load($tpl->smarty, $_file_to_check[2]); + if ($handler->checkTimestamps()) { + $source = Smarty_Template_Source::load($tpl, $tpl->smarty, $_file_to_check[ 0 ]); + $mtime = $source->getTimeStamp(); + } else { + continue; + } } if (!$mtime || $mtime > $_file_to_check[1]) { $is_valid = false; diff --git a/libs/sysplugins/smarty_resource.php b/libs/sysplugins/smarty_resource.php index 72611255..93d9fa7a 100644 --- a/libs/sysplugins/smarty_resource.php +++ b/libs/sysplugins/smarty_resource.php @@ -240,6 +240,16 @@ abstract class Smarty_Resource return $resource->buildUniqueResourceName($smarty, $name); } + /* + * Check if resource must check time stamps when when loading complied or cached templates. + * Resources like 'extends' which use source components my disable timestamp checks on own resource. + * + * @return bool + */ + public function checkTimestamps() { + return true; + } + /** * initialize Source Object for given resource * wrapper for backward compatibility to versions < 3.1.22