- optimization improve speed of filetime checks on extends and extendsall resource

This commit is contained in:
uwetews
2015-12-21 02:18:27 +01:00
parent 3548de5fa1
commit efaa61cfb6
6 changed files with 49 additions and 15 deletions

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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