Skip to content

Commit b417ebd

Browse files
author
Maksym Savich
committed
MAGETWO-35462: Refactor \Magento\Framework\Model\Resource\Db\AbstractDb only update changed fields
- CR changes
1 parent 7f156da commit b417ebd

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

lib/internal/Magento/Framework/Model/Resource/Db/AbstractDb.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,7 @@ public function save(\Magento\Framework\Model\AbstractModel $object)
417417
* Not auto increment primary key support
418418
*/
419419
if ($this->_isPkAutoIncrement) {
420-
$data = $this->_prepareDataForSave($object);
421-
unset($data[$this->getIdFieldName()]);
422-
$data = $this->prepareDataForUpdate($data, $object->getStoredData());
420+
$data = $this->prepareDataForUpdate($object);
423421
if (!empty($data)) {
424422
$this->_getWriteAdapter()->update($this->getMainTable(), $data, $condition);
425423
}
@@ -431,9 +429,7 @@ public function save(\Magento\Framework\Model\AbstractModel $object)
431429
$condition
432430
);
433431
if ($this->_getWriteAdapter()->fetchOne($select) !== false) {
434-
$data = $this->_prepareDataForSave($object);
435-
unset($data[$this->getIdFieldName()]);
436-
$data = $this->prepareDataForUpdate($data, $object->getStoredData());
432+
$data = $this->prepareDataForUpdate($object);
437433
if (!empty($data)) {
438434
$this->_getWriteAdapter()->update($this->getMainTable(), $data, $condition);
439435
}
@@ -778,17 +774,20 @@ public function getChecksum($table)
778774
/**
779775
* Get the array of data fields that was changed or added
780776
*
781-
* @param array $data
782-
* @param array $storedData
777+
* @param \Magento\Framework\Model\AbstractModel $object
783778
* @return array
784779
*/
785-
protected function prepareDataForUpdate($data, $storedData)
780+
protected function prepareDataForUpdate($object)
786781
{
787-
foreach ($storedData as $key => $value) {
782+
$data = $this->_prepareDataForSave($object);
783+
unset($data[$this->getIdFieldName()]);
784+
785+
foreach ($object->getStoredData() as $key => $value) {
788786
if(array_key_exists($key, $data) && $data[$key] == $value) {
789787
unset($data[$key]);
790788
}
791789
}
790+
792791
return $data;
793792
}
794793
}

0 commit comments

Comments
 (0)