Skip to content

Commit

Permalink
Dev: added static cache for getInstanceFromTemplateName
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Dec 21, 2017
1 parent 09cfdff commit 5e46ec2
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions application/models/TemplateConfiguration.php
Expand Up @@ -59,6 +59,9 @@ class TemplateConfiguration extends TemplateConfig
/** @var string $sPreviewImgTag the template preview image tag for the template list*/
public $sPreviewImgTag;

/** @var array $aInstancesFromTemplateName cache for method getInstanceFromTemplateName*/
public static $aInstancesFromTemplateName;

/** @var boolean $bTemplateCheckResult is the template valid?*/
private $bTemplateCheckResult;

Expand Down Expand Up @@ -140,6 +143,10 @@ public function attributeLabels()
*/
public static function getInstanceFromTemplateName($sTemplateName)
{
if (!empty(self::$aInstancesFromTemplateName[$sTemplateName])){
return self::$aInstancesFromTemplateName[$sTemplateName];
}

$oInstance = self::model()->find(
'template_name=:template_name AND sid IS NULL AND gsid IS NULL',
array(':template_name'=>$sTemplateName)
Expand All @@ -150,6 +157,8 @@ public static function getInstanceFromTemplateName($sTemplateName)
$oInstance = self::getInstanceFromTemplateName(getGlobalSetting('defaulttheme'));
}

self::$aInstancesFromTemplateName[$sTemplateName] = $oInstance;

return $oInstance;
}

Expand All @@ -163,7 +172,6 @@ public static function getInstanceFromTemplateName($sTemplateName)
*/
public static function getInstanceFromSurveyGroup($iSurveyGroupId, $sTemplateName = null)
{

//if a template name is given also check against that
$sTemplateName = $sTemplateName != null ? $sTemplateName : SurveysGroups::model()->findByPk($iSurveyGroupId)->template;

Expand All @@ -185,7 +193,6 @@ public static function getInstanceFromSurveyGroup($iSurveyGroupId, $sTemplateNam
}

return $oTemplateConfigurationModel;

}

/**
Expand Down

0 comments on commit 5e46ec2

Please sign in to comment.