Skip to content

Commit

Permalink
Fixed issue: Slow performance on every admininstration page if you ha…
Browse files Browse the repository at this point in the history
…ve alot of surveys
  • Loading branch information
c-schmitz committed Jan 17, 2018
1 parent 4415de3 commit 79c3ccd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
4 changes: 2 additions & 2 deletions application/controllers/admin/index.php
Expand Up @@ -71,8 +71,8 @@ public function run()
$aData['showLastQuestion'] = false;
}

$aData['countSurveyList'] = count((array) getSurveyList(true));

$aData['countSurveyList'] = Survey::model()->count();
// We get the home page display setting
$aData['bShowSurveyList'] = (getGlobalSetting('show_survey_list') == "show");
$aData['bShowSurveyListSearch'] = (getGlobalSetting('show_survey_list_search') == "show");
Expand Down
11 changes: 2 additions & 9 deletions application/helpers/common_helper.php
Expand Up @@ -106,17 +106,10 @@ function getSurveyList($bReturnArray = false)
if (is_null($cached)) {
$surveyidresult = Survey::model()
->permission(Yii::app()->user->getId())
->with('languagesettings')
->findAll();
foreach ($surveyidresult as $result) {
if (!empty($result->defaultlanguage)) {
$surveynames[] = array_merge($result->attributes, $result->defaultlanguage->attributes);
} elseif (!($bCheckIntegrity)) {
$bCheckIntegrity = true;
Yii::app()->setFlashMessage(
CHtml::link(gT("One or more surveys seem to be broken - please use the data integrity check tool to fix this."), array("admin/checkintegrity"))
,
'error');
}
$surveynames[] = array_merge($result->attributes,$result->languagesettings[$result->language]->attributes);
}

usort($surveynames, function($a, $b)
Expand Down
25 changes: 12 additions & 13 deletions application/models/Survey.php
Expand Up @@ -186,7 +186,7 @@ public function init()
$this->template = Template::templateNameFilter(getGlobalSetting('defaulttheme'));
$validator = new LSYii_Validators;
$this->language = $validator->languageFilter(Yii::app()->getConfig('defaultlang'));
$this->attachEventHandler("onAfterFind", array($this, 'fixSurveyAttribute'));
$this->attachEventHandler("onAfterFind", array($this, 'afterFindSurvey'));
}

/** @inheritdoc */
Expand Down Expand Up @@ -289,15 +289,15 @@ public static function model($class = __CLASS__)
public function relations()
{
return array(
'permissions' => array(self::HAS_MANY, 'Permission', array('entity_id'=> 'sid'), 'together' => true), //
'languagesettings' => array(self::HAS_MANY, 'SurveyLanguageSetting', 'surveyls_survey_id', 'index' => 'surveyls_language', 'together' => true),
'defaultlanguage' => array(self::BELONGS_TO, 'SurveyLanguageSetting', array('language' => 'surveyls_language', 'sid' => 'surveyls_survey_id'), 'together' => true),
'correct_relation_defaultlanguage' => array(self::HAS_ONE, 'SurveyLanguageSetting', array('surveyls_language' => 'language', 'surveyls_survey_id' => 'sid'), 'together' => true),
'owner' => array(self::BELONGS_TO, 'User', 'owner_id', 'together' => true),
'groups' => array(self::HAS_MANY, 'QuestionGroup', 'sid', 'together' => true, 'order'=>'group_order ASC'),
'permissions' => array(self::HAS_MANY, 'Permission', array('entity_id'=> 'sid')), //
'languagesettings' => array(self::HAS_MANY, 'SurveyLanguageSetting', 'surveyls_survey_id', 'index' => 'surveyls_language'),
'defaultlanguage' => array(self::BELONGS_TO, 'SurveyLanguageSetting', array('language' => 'surveyls_language', 'sid' => 'surveyls_survey_id')),
'correct_relation_defaultlanguage' => array(self::HAS_ONE, 'SurveyLanguageSetting', array('surveyls_language' => 'language', 'surveyls_survey_id' => 'sid')),
'owner' => array(self::BELONGS_TO, 'User', 'owner_id',),
'groups' => array(self::HAS_MANY, 'QuestionGroup', 'sid', 'order'=>'group_order ASC'),
'quotas' => array(self::HAS_MANY, 'Quota', 'sid', 'order'=>'name ASC'),
'surveymenus' => array(self::HAS_MANY, 'Surveymenu', array('survey_id' => 'sid')),
'surveygroup' => array(self::BELONGS_TO, 'SurveysGroups', array('gsid' => 'gsid'), 'together' => true),
'surveygroup' => array(self::BELONGS_TO, 'SurveysGroups', array('gsid' => 'gsid')),
'templateModel' => array(self::HAS_ONE, 'Template', array('name' => 'template'))
);
}
Expand Down Expand Up @@ -392,24 +392,23 @@ public function rules()


/**
* fixSurveyAttribute to fix and/or add some survey attribute
* afterFindSurvey to fix and/or add some survey attribute
* - Fix template name to be sure template exist
*/
public function fixSurveyAttribute()
public function afterFindSurvey()
{
$event = new PluginEvent('afterFindSurvey');
$event = new PluginEvent('afterFindSurvey');
$event->set('surveyid', $this->sid);
App()->getPluginManager()->dispatchEvent($event);
// set the attributes we allow to be fixed
$allowedAttributes = array('template', 'usecookie', 'allowprev',
$allowedAttributes = array( 'template', 'usecookie', 'allowprev',
'showxquestions', 'shownoanswer', 'showprogress', 'questionindex',
'usecaptcha', 'showgroupinfo', 'showqnumcode', 'navigationdelay');
foreach ($allowedAttributes as $attribute) {
if (!is_null($event->get($attribute))) {
$this->{$attribute} = $event->get($attribute);
}
}
$this->template = Template::templateNameFilter($this->template);
}


Expand Down
5 changes: 5 additions & 0 deletions application/models/SurveyLanguageSetting.php
Expand Up @@ -123,6 +123,11 @@ public function rules()
array('surveyls_numberformat', 'numerical', 'integerOnly'=>true, 'min'=>'0', 'max'=>'1', 'allowEmpty'=>true),
);
}

public function defaultScope()
{
return array('index'=>'surveyls_language');
}

/**
* Defines the customs validation rule lsdefault
Expand Down

0 comments on commit 79c3ccd

Please sign in to comment.