Skip to content

Commit

Permalink
dev: speed up survey listing by not loading the model (show columns /…
Browse files Browse the repository at this point in the history
…create etc.)
  • Loading branch information
mennodekker committed Dec 13, 2012
1 parent 438becc commit 737bfe8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
12 changes: 6 additions & 6 deletions application/controllers/admin/surveyadmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,9 @@ public function getSurveys_json()
//Set Responses
if ($rows['active'] == "Y")
{
$partial = Survey_dynamic::model($rows['sid'])->countByAttributes(array('submitdate' => null));
$all = Survey_dynamic::model($rows['sid'])->count();
$cntResult = Survey_dynamic::countAllAndPartial($rows['sid']);
$all = $cntResult['cntAll'];
$partial = $cntResult['cntPartial'];

$aSurveyEntry[] = $all - $partial;
$aSurveyEntry[] = $partial;
Expand All @@ -696,10 +697,9 @@ public function getSurveys_json()
$aSurveyEntry['viewurl'] = $this->getController()->createUrl("/admin/survey/sa/view/surveyid/" . $rows['sid']);
if (tableExists('tokens_' . $rows['sid'] ))
{
$tokens = Tokens_dynamic::model($rows['sid'])->count();
$tokenscompleted = Tokens_dynamic::model($rows['sid'])->count(array(
'condition' => "completed <> 'N'"
));
$cntResult = Tokens_dynamic::countAllAndCompleted($rows['sid']);
$tokens = $cntResult['cntAll'];
$tokenscompleted = $cntResult['cntCompleted'];

$aSurveyEntry[] = $tokens;
$aSurveyEntry[] = ($tokens == 0) ? 0 : round($tokenscompleted / $tokens * 100, 1);
Expand Down
13 changes: 13 additions & 0 deletions application/models/Survey_dynamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,19 @@ public function addTokenCriteria($condition)
return $newCriteria;
}

public static function countAllAndPartial($sid)
{
$select = array(
'count(*) AS cntAll',
'sum(CASE
WHEN submitdate IS NULL THEN 1
ELSE 0
END) AS cntPartial',
);
$result = Yii::app()->db->createCommand()->select($select)->from('{{survey_' . $sid . '}}')->queryRow();
return $result;
}

/**
* Return true if actual survey is completed
*
Expand Down
13 changes: 13 additions & 0 deletions application/models/Tokens_dynamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,19 @@ function selectEmptyTokens($iSurveyID)
{
return Yii::app()->db->createCommand("SELECT tid FROM {{tokens_{$iSurveyID}}} WHERE token IS NULL OR token=''")->queryAll();
}

public static function countAllAndCompleted($sid)
{
$select = array(
'count(*) AS cntAll',
'sum(CASE completed
WHEN "Y" THEN 0
ELSE 1
END) AS cntCompleted',
);
$result = Yii::app()->db->createCommand()->select($select)->from('{{tokens_' . $sid . '}}')->queryRow();
return $result;
}

/**
* Creates and inserts token for a specific token record and returns the token string created
Expand Down

0 comments on commit 737bfe8

Please sign in to comment.