From 5e8a6816f431e0a535984308b84e6285f86ac5a6 Mon Sep 17 00:00:00 2001 From: bethrezen Date: Tue, 24 Feb 2015 11:05:59 +0300 Subject: [PATCH] Improve Helper::getModelMap #171 - add asArray() for better performance --- application/components/Helper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/application/components/Helper.php b/application/components/Helper.php index 9b7f06011..ef6c900c7 100644 --- a/application/components/Helper.php +++ b/application/components/Helper.php @@ -26,12 +26,12 @@ class Helper public static function getModelMap($className, $keyAttribute, $valueAttribute, $useCache = true) { /** @var ActiveRecord $className */ - $cacheKey = 'Map: ' . $className::tableName() . ':' . $keyAttribute . ':' . $valueAttribute; + $cacheKey = '1Map: ' . $className::tableName() . ':' . $keyAttribute . ':' . $valueAttribute; if (isset(Helper::$modelMaps[$cacheKey]) === false) { Helper::$modelMaps[$cacheKey] = $useCache ? Yii::$app->cache->get($cacheKey) : false; if (Helper::$modelMaps[$cacheKey] === false) { - Helper::$modelMaps[$cacheKey] = ArrayHelper::map($className::find()->all(), $keyAttribute, $valueAttribute); - if ($useCache) { + Helper::$modelMaps[$cacheKey] = ArrayHelper::map($className::find()->asArray()->all(), $keyAttribute, $valueAttribute); + if ($useCache === true) { Yii::$app->cache->set( $cacheKey, Helper::$modelMaps[$cacheKey],