diff --git a/application/models/Settings_global.php b/application/models/Settings_global.php index 86d712c265f..f1250c2b8c9 100644 --- a/application/models/Settings_global.php +++ b/application/models/Settings_global.php @@ -16,6 +16,7 @@ class Settings_global extends CActiveRecord { + protected $resultCache = array(); /** * Returns the static model of Settings table * @@ -72,5 +73,25 @@ function updateSetting($settingname, $settingvalue) } } + + public function findAll($condition = '', $params = array()) { + $result = parent::findAll($condition, $params); + if (empty($condition) && empty($params)) { + // Only is there a re no conditions, we cache the results + foreach($result as $row) { + $this->resultCache[$row['stg_name']] = $row; + } + } + return $result; + } + + public function findByPk($pk, $condition = '', $params = array()) { + if (empty($condition) && empty($params)) { + if (!empty($this->resultCache) && array_key_exists($pk, $this->resultCache)) { + return $this->resultCache[$pk]; + } + } + return parent::findByPk($pk, $condition, $params); + } } ?> diff --git a/application/models/Survey.php b/application/models/Survey.php index 565c07ac94a..0a5b7766843 100644 --- a/application/models/Survey.php +++ b/application/models/Survey.php @@ -353,4 +353,20 @@ public function deleteSurvey($iSurveyID, $recursive=true) Quota::model()->deleteQuota(array('sid' => $iSurveyID), true); } } + + public function findByPk($pk, $condition = '', $params = array()) { + static $lastResult = array(); + if (empty($condition) && empty($params)) { + if (array_key_exists($pk, $lastResult)) { + return $lastResult[$pk]; + } else { + $result = parent::findByPk($pk, $condition, $params); + $lastResult[$pk] = $result; + + return $result; + } + } + + return parent::findByPk($pk, $condition, $params); + } }