Skip to content

Commit

Permalink
dev: some improvements to survey runtime by caching
Browse files Browse the repository at this point in the history
  • Loading branch information
mennodekker committed Nov 11, 2012
1 parent 47d89ee commit 88f2447
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
17 changes: 12 additions & 5 deletions application/helpers/frontend_helper.php
Expand Up @@ -2054,7 +2054,7 @@ function surveymover()
*/
function doAssessment($surveyid, $returndataonly=false)
{

static $assesmentQuery = array();
$clang = Yii::app()->lang;

$baselang=Survey::model()->findByPk($surveyid)->language;
Expand All @@ -2063,10 +2063,17 @@ function doAssessment($surveyid, $returndataonly=false)
{
$_SESSION['survey_'.$surveyid]['s_lang']=$baselang;
}
$query = "SELECT * FROM {{assessments}}
WHERE sid=$surveyid and language='".$_SESSION['survey_'.$surveyid]['s_lang']."'
ORDER BY scope, id";
if ($result = dbExecuteAssoc($query)) //Checked
if (array_key_exists($surveyid, $assesmentQuery) && array_key_exists($_SESSION['survey_'.$surveyid]['s_lang'], $assesmentQuery[$surveyid])) {
$result = $assesmentQuery[$surveyid][$_SESSION['survey_'.$surveyid]['s_lang']];
} else {
$query = "SELECT * FROM {{assessments}}
WHERE sid=$surveyid and language='".$_SESSION['survey_'.$surveyid]['s_lang']."'
ORDER BY scope, id";
$result = dbExecuteAssoc($query);
$assesmentQuery[$surveyid][$_SESSION['survey_'.$surveyid]['s_lang']] = $result;
}

if ($result) //Checked
{
$aResultSet=$result->readAll();
if (count($aResultSet) > 0)
Expand Down
6 changes: 6 additions & 0 deletions application/models/Survey_dynamic.php
Expand Up @@ -192,7 +192,12 @@ public function addTokenCriteria($condition)
*/
public function isCompleted($srid)
{
static $resultCache = array();

$sid = self::$sid;
if (array_key_exists($sid, $resultCache) && array_key_exists($srid, $resultCache[$sid])) {
return $resultCache[$sid][$srid];
}
$completed=false;

if(Yii::app()->db->schema->getTable($this->tableName())){
Expand All @@ -206,6 +211,7 @@ public function isCompleted($srid)
$completed=true;
}
}
$resultCache[$sid][$srid] = $completed;
return $completed;
}

Expand Down

0 comments on commit 88f2447

Please sign in to comment.