Commit 7e0c6353 by Carsten Brandt

optimized redis AR insert

parent ece300ac
...@@ -120,16 +120,14 @@ class ActiveRecord extends BaseActiveRecord ...@@ -120,16 +120,14 @@ class ActiveRecord extends BaseActiveRecord
$key = static::keyPrefix() . ':a:' . static::buildKey($pk); $key = static::keyPrefix() . ':a:' . static::buildKey($pk);
// save attributes // save attributes
$setArgs = [$key]; $setArgs = [$key];
$delArgs = [$key];
foreach ($values as $attribute => $value) { foreach ($values as $attribute => $value) {
// only insert attributes that are not null
if ($value !== null) { if ($value !== null) {
if (is_bool($value)) { if (is_bool($value)) {
$value = (int)$value; $value = (int)$value;
} }
$setArgs[] = $attribute; $setArgs[] = $attribute;
$setArgs[] = $value; $setArgs[] = $value;
} else {
$delArgs[] = $attribute;
} }
} }
...@@ -137,10 +135,6 @@ class ActiveRecord extends BaseActiveRecord ...@@ -137,10 +135,6 @@ class ActiveRecord extends BaseActiveRecord
$db->executeCommand('HMSET', $setArgs); $db->executeCommand('HMSET', $setArgs);
} }
if (count($delArgs) > 1) {
$db->executeCommand('HDEL', $delArgs);
}
$changedAttributes = array_fill_keys(array_keys($values), null); $changedAttributes = array_fill_keys(array_keys($values), null);
$this->setOldAttributes($values); $this->setOldAttributes($values);
$this->afterSave(true, $changedAttributes); $this->afterSave(true, $changedAttributes);
......
...@@ -4,6 +4,7 @@ Yii Framework 2 redis extension Change Log ...@@ -4,6 +4,7 @@ Yii Framework 2 redis extension Change Log
2.0.0-rc under development 2.0.0-rc under development
-------------------------- --------------------------
- Bug #1311: Fixed storage and finding of `null` and boolean values (samdark, cebe)
- Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe) - Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe)
- Enh #4048: Added `init` event to `ActiveQuery` classes (qiangxue) - Enh #4048: Added `init` event to `ActiveQuery` classes (qiangxue)
- Enh #4086: changedAttributes of afterSave Event now contain old values (dizews) - Enh #4086: changedAttributes of afterSave Event now contain old values (dizews)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment