Skip to content

Commit

Permalink
Improve Helper::getModelMap #171 - add asArray() for better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
bethrezen committed Feb 24, 2015
1 parent 25da19a commit 5e8a681
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions application/components/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit 5e8a681

Please sign in to comment.