Skip to content

Commit

Permalink
Fixed issue #6567: Performance issue
Browse files Browse the repository at this point in the history
Dev This commit changes the way attributes are extracted for superadmins only
  • Loading branch information
aniesshsethh committed Oct 30, 2012
1 parent 76983ca commit 3c6ea94
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
30 changes: 11 additions & 19 deletions application/controllers/admin/participantsaction.php
Expand Up @@ -1039,7 +1039,7 @@ function subval_sort($a, $subkey, $order)

$page = Yii::app()->request->getPost('page');
$limit = Yii::app()->request->getPost('rows');
$limit = isset($limit) ? $limit : 50; //Stop division by zero errors
$limit = isset($limit) ? $limit : 50; //Stop division by zero errors

$attid = ParticipantAttributeNames::model()->getVisibleAttributes();
$participantfields = array('participant_id', 'can_edit', 'firstname', 'lastname', 'email', 'blacklisted', 'survey', 'language', 'owner_uid');
Expand All @@ -1051,35 +1051,27 @@ function subval_sort($a, $subkey, $order)
//If super admin all the participants will be visible
if (Yii::app()->session['USER_RIGHT_SUPERADMIN'])
{
$records = Participants::model()->getParticipants($page, $limit);
$records = Participants::model()->getParticipants($page, $limit,$attid);
$aData = new stdClass;
$aData->page = $page;
$aData->records = Participants::model()->count();
$aData->total = ceil($aData->records / $limit);
$i = 0;
$sortablearray=array();
foreach ($records as $key => $row)
{
$username = User::model()->getName($row['owner_uid']); //for conversion of uid to human readable names
$sortablearray=array();
foreach ($records as $key => $row)
{
$surveycount = Participants::model()->getSurveyCount($row['participant_id']);
$sortablearray[$i] = array($row['participant_id'], "true", $row['firstname'], $row['lastname'], $row['email'], $row['blacklisted'], $surveycount, $row['language'], $username[0]['full_name']); // since it's the admin he has access to all editing on the participants inspite of what can_edit option is
foreach ($attid as $iAttributeId)
$sortablearray[$i] = array($row['participant_id'], "true", $row['firstname'], $row['lastname'], $row['email'], $row['blacklisted'], $surveycount, $row['language'], $row['ownername']); // since it's the admin he has access to all editing on the participants inspite of what can_edit option is
unset($row['participant_id'], $row['firstname'], $row['lastname'], $row['email'], $row['blacklisted'], $row['language'],$row['ownername'],$row['owner_uid']);
foreach($row as $key=>$attvalue)
{
$answer = ParticipantAttributeNames::model()->getAttributeValue($row['participant_id'], $iAttributeId['attribute_id']);
if (isset($answer['value']))
{
array_push($sortablearray[$i], $answer['value']);
}
else
{
array_push($sortablearray[$i], "");
}
}
array_push($sortablearray[$i], $attvalue);
}
$i++;
}

$indexsort = array_search(Yii::app()->request->getPost('sidx'), $participantfields);
if(!empty($sortablearray)) {
if(!empty($sortablearray)) {
$sortedarray = subval_sort($sortablearray, $indexsort, Yii::app()->request->getPost('sord'));
$i = 0;
$count = count($sortedarray[0]);
Expand Down
23 changes: 20 additions & 3 deletions application/models/Participants.php
Expand Up @@ -205,11 +205,28 @@ function getParticipantsSharedCount($userid)
return count(Yii::app()->db->createCommand()->select('{{participants}}.*, {{participant_shares}}.*')->from('{{participants}}')->join('{{participant_shares}}', '{{participant_shares}}.participant_id = {{participants}}.participant_id')->where('owner_uid = :userid')->bindParam(":userid", $userid, PDO::PARAM_INT)->queryAll());
}

function getParticipants($page, $limit)
function getParticipants($page, $limit,$attid)
{
$start = $limit * $page - $limit;
$data = Yii::app()->db->createCommand()->select('*')->from('{{participants}}')->limit($limit, $start)->queryAll();
return $data;
$selectValue = array();
$joinValue = array();
array_push($selectValue,"p.*");
array_push($selectValue,"luser.full_name as ownername");
array_push($joinValue,"left join lime_users luser ON luser.uid=p.owner_uid");
foreach($attid as $key=>$attid)
{
$attid = $attid['attribute_id'];
array_push($selectValue,"attribute".$attid.".value as a".$attid);
array_push($joinValue,"LEFT JOIN {{participant_attribute}} attribute".$attid." ON attribute".$attid.".participant_id=p.participant_id AND attribute".$attid.".attribute_id=".$attid);
}
$data = Yii::app()->db->createCommand()
->select($selectValue)
->from('{{participants}} p')
->limit($limit, $start);
$data->setJoin($joinValue);
$allData = $data->queryAll();
return $allData;

}

function getSurveyCount($participant_id)
Expand Down

0 comments on commit 3c6ea94

Please sign in to comment.