Skip to content

Commit

Permalink
optimize Multiline save if a lot of records are unchanged
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Oct 3, 2023
1 parent 351d6bf commit 619df7f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Form/Control/Multiline.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ public function saveRows(): self
$currentIds = array_column($model->export(), $model->idField);

foreach ($this->rowData as $row) {
$entity = $row[$model->idField] !== null ? $model->load($row[$model->idField]) : $model->createEntity();
$entity = $row[$model->idField] !== null
? $model->load($row[$model->idField])
: $model->createEntity();
foreach ($row as $fieldName => $value) {
if ($fieldName === '__atkml') {
continue;
Expand All @@ -350,9 +352,12 @@ public function saveRows(): self
$entity->set($fieldName, $value);
}
}
$id = $entity->save()->getId();

$k = array_search($id, $currentIds, true);
if (!$entity->isLoaded() || $entity->getDirtyRef() !== []) {
$entity->save();
}

$k = array_search($entity->getId(), $currentIds, true);
if ($k !== false) {
unset($currentIds[$k]);
}
Expand Down

0 comments on commit 619df7f

Please sign in to comment.