Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue #CT-652: system slowness when saving survey settings #3740

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
6 changes: 4 additions & 2 deletions application/models/QuestionTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,11 @@ public static function getQuestionXMLPathForBaseType($type)
{
static $questionThemeCache = [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike to use Cache for Static var … Static is not caching ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah makes sense, cant use it everywhere php will run out of memory eventually when we use it to much. Will look at yii's caching

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently : it's a static var :). I don't ask to put it in cache (maybe in future), just more clear name :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also propose the creation of a protected static $questionThemeCache = []; data member to make the file more readable and the cache more accessible.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protected static $questionThemeStatic = [] ;)

if (!array_key_exists($type, $questionThemeCache)) {
$questionThemeCache[$type] = self::model()->findByAttributes([],
$questionThemeCache[$type] = self::model()->findByAttributes(
[],
'question_type = :question_type AND extends = :extends',
['question_type' => $type, 'extends' => '']);
['question_type' => $type, 'extends' => '']
);
}
$questionTheme = $questionThemeCache[$type];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ protected function getAttributesFromQuestionTheme($questionThemeName, $questionT
/** @var array<string,array> An array of question attributes */
$attributes = array();

static $questionThemeCache = [];
if (!array_key_exists($questionType, $questionThemeCache)) {
/** @var QuestionTheme|null $questionThemeCache */
$questionThemeCache[$questionType] = QuestionTheme::model()->findByAttributes([], 'name = :name AND extends = :extends', ['name' => $questionThemeName, 'extends' => $questionType]);
}
$questionTheme = $questionThemeCache[$questionType];
$questionTheme = \QuestionTheme::model()->findByAttributes([], 'name = :name AND extends = :extends', ['name' => $questionThemeName, 'extends' => $questionType]);
if ($questionTheme !== null) {
$xmlFilePath = $questionTheme->getXmlPath() . '/config.xml';
$extensionConfig = \ExtensionConfig::loadFromFile($xmlFilePath);
Expand Down