mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
- optimization of sub-template processing
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
===== 3.1.30-dev ===== (xx.xx.xx)
|
||||
14.02.2016
|
||||
- new tag {make_nocache} read NEW_FEATURES.txt https://github.com/smarty-php/smarty/issues/110
|
||||
- optimization of sub-template processing
|
||||
|
||||
11.02.2016
|
||||
- improvement added KnockoutJS comments to trimwhitespace outputfilter https://github.com/smarty-php/smarty/issues/82
|
||||
|
@@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '3.1.30-dev/39';
|
||||
const SMARTY_VERSION = '3.1.30-dev/40';
|
||||
|
||||
/**
|
||||
* define variable scopes
|
||||
@@ -1108,6 +1108,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
*/
|
||||
public function _getTemplateId($template_name, $cache_id = null, $compile_id = null, $caching = null)
|
||||
{
|
||||
$template_name = (strpos($template_name, ':') === false) ? "{$this->default_resource_type}:{$template_name}" : $template_name;
|
||||
$cache_id = $cache_id === null ? $this->cache_id : $cache_id;
|
||||
$compile_id = $compile_id === null ? $this->compile_id : $compile_id;
|
||||
$caching = (int) ($caching === null ? $this->caching : $caching);
|
||||
|
@@ -95,9 +95,17 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
if (isset($compiled->includes[ $fullResourceName ])) {
|
||||
$compiled->includes[ $fullResourceName ] ++;
|
||||
$cache_tpl = true;
|
||||
} else {
|
||||
if ("{$compiler->template->source->type}:{$compiler->template->source->name}" ==
|
||||
$fullResourceName
|
||||
) {
|
||||
// recursive call of current template
|
||||
$compiled->includes[ $fullResourceName ] = 2;
|
||||
$cache_tpl = true;
|
||||
} else {
|
||||
$compiled->includes[ $fullResourceName ] = 1;
|
||||
}
|
||||
}
|
||||
$fullResourceName = '"' . $fullResourceName . '"';
|
||||
}
|
||||
}
|
||||
|
@@ -239,39 +239,40 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||
public function _subTemplateRender($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $scope,
|
||||
$forceTplCache, $uid = null, $content_func = null)
|
||||
{
|
||||
$_templateId = $this->smarty->_getTemplateId($template, $cache_id, $compile_id, $caching);
|
||||
// already in template cache?
|
||||
/* @var Smarty_Internal_Template $tpl */
|
||||
if (isset($this->smarty->_cache[ 'tplObjects' ][ $_templateId ])) {
|
||||
// clone cached template object because of possible recursive call
|
||||
$tpl = clone $this->smarty->_cache[ 'tplObjects' ][ $_templateId ];
|
||||
// get variables from calling scope
|
||||
$tpl->tpl_vars = $this->tpl_vars;
|
||||
$tpl->config_vars = $this->config_vars;
|
||||
$tpl = clone $this;
|
||||
$tpl->parent = $this;
|
||||
// get template functions
|
||||
$tpl->tpl_function = $this->tpl_function;
|
||||
// copy inheritance object?
|
||||
if (isset($this->ext->_inheritance)) {
|
||||
$tpl->ext->_inheritance = $this->ext->_inheritance;
|
||||
} else {
|
||||
unset($tpl->ext->_inheritance);
|
||||
}
|
||||
$_templateId = $this->smarty->_getTemplateId($template, $cache_id, $compile_id, $caching);
|
||||
// recursive call ?
|
||||
if ($tpl->_getTemplateId() != $_templateId) {
|
||||
// already in template cache?
|
||||
if (isset($this->smarty->_cache[ 'tplObjects' ][ $_templateId ])) {
|
||||
// copy data from cached object
|
||||
$cachedTpl = &$this->smarty->_cache[ 'tplObjects' ][ $_templateId ];
|
||||
$tpl->templateId = $cachedTpl->templateId;
|
||||
$tpl->template_resource = $cachedTpl->template_resource;
|
||||
$tpl->cache_id = $cachedTpl->cache_id;
|
||||
$tpl->compile_id = $cachedTpl->compile_id;
|
||||
$tpl->source = $cachedTpl->source;
|
||||
// if $caching mode changed the compiled resource is invalid
|
||||
if ((bool) $tpl->caching !== (bool) $caching) {
|
||||
unset($tpl->compiled);
|
||||
} elseif (isset($cachedTpl->compiled)) {
|
||||
$tpl->compiled = $cachedTpl->compiled;
|
||||
} else {
|
||||
unset($tpl->compiled);
|
||||
}
|
||||
if ($caching != 9999 && isset($cachedTpl->cached)) {
|
||||
$tpl->cached = $cachedTpl->cached;
|
||||
} else {
|
||||
unset($tpl->cached);
|
||||
}
|
||||
} else {
|
||||
$tpl = clone $this;
|
||||
$tpl->parent = $this;
|
||||
if (!isset($tpl->templateId) || $tpl->templateId !== $_templateId) {
|
||||
$tpl->templateId = $_templateId;
|
||||
$tpl->template_resource = $template;
|
||||
$tpl->cache_id = $cache_id;
|
||||
$tpl->compile_id = $compile_id;
|
||||
if (isset($uid)) {
|
||||
// for inline templates we can get all resource information from file dependency
|
||||
if (isset($tpl->compiled->file_dependency[ $uid ])) {
|
||||
list($filepath, $timestamp, $type) = $tpl->compiled->file_dependency[ $uid ];
|
||||
$tpl->source =
|
||||
new Smarty_Template_Source(isset($tpl->smarty->_cache[ 'resource_handlers' ][ $type ]) ?
|
||||
@@ -283,33 +284,26 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||
$tpl->source->exists = true;
|
||||
$tpl->source->uid = $uid;
|
||||
} else {
|
||||
$tpl->source = null;
|
||||
}
|
||||
} else {
|
||||
$tpl->source = null;
|
||||
}
|
||||
if (!isset($tpl->source)) {
|
||||
$tpl->source = Smarty_Template_Source::load($tpl);
|
||||
unset($tpl->compiled);
|
||||
}
|
||||
if ($caching != 9999) {
|
||||
unset($tpl->cached);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// on recursive calls force caching
|
||||
$forceTplCache = true;
|
||||
}
|
||||
$tpl->caching = $caching;
|
||||
$tpl->cache_lifetime = $cache_lifetime;
|
||||
if ($caching == 9999) {
|
||||
$tpl->cached = $this->cached;
|
||||
}
|
||||
// set template scope
|
||||
$tpl->scope = $scope;
|
||||
if (!isset($tpl->smarty->_cache[ 'tplObjects' ][ $tpl->templateId ]) && !$tpl->source->handler->recompiled) {
|
||||
// if template is called multiple times set flag to to cache template objects
|
||||
$forceTplCache = $forceTplCache ||
|
||||
(isset($tpl->smarty->_cache[ 'subTplInfo' ][ $tpl->template_resource ]) &&
|
||||
$tpl->smarty->_cache[ 'subTplInfo' ][ $tpl->template_resource ] > 1);
|
||||
// check if template object should be cached
|
||||
if ($tpl->_isParentTemplate() && isset($tpl->smarty->_cache[ 'tplObjects' ][ $tpl->parent->templateId ]) ||
|
||||
$forceTplCache
|
||||
if ($forceTplCache || (isset($tpl->smarty->_cache[ 'subTplInfo' ][ $tpl->template_resource ]) &&
|
||||
$tpl->smarty->_cache[ 'subTplInfo' ][ $tpl->template_resource ] > 1) ||
|
||||
($tpl->_isParentTemplate() && isset($tpl->smarty->_cache[ 'tplObjects' ][ $tpl->parent->templateId ]))
|
||||
) {
|
||||
$tpl->smarty->_cache[ 'tplObjects' ][ $tpl->templateId ] = $tpl;
|
||||
}
|
||||
|
Reference in New Issue
Block a user