Skip to content

Commit 8a3d87d

Browse files
authored
Merge pull request #20 from dmstr/feature/optimize-editor-save-models
Optimize prototype\models\Edit::save()
2 parents 53d6b7b + b24f07d commit 8a3d87d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/models/Edit.php

+7
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ public function save()
126126
$model->key = $this->keys[$modelId];
127127
$model->value = $this->values[$modelId];
128128

129+
// save only if anything changed to prevent unnecessary validation and saving which can be expensive
130+
// (eg. each less will be compiled while validate)
131+
if (!$model->getIsNewRecord() && empty($model->getDirtyAttributes())) {
132+
Yii::debug('Nothing changed in model id: ' . $model->id . ' -> continue', __METHOD__);
133+
continue;
134+
}
135+
129136
if ($model->save() === false) {
130137
$transaction->rollBack();
131138
return false;

0 commit comments

Comments
 (0)