Skip to content

Commit aefa7d9

Browse files
author
Oleksandr Iegorov
committed
MC-19791: Poor performance on sales order update - string to integer
1 parent 29f99e6 commit aefa7d9

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,24 @@ protected function saveNewObject(\Magento\Framework\Model\AbstractModel $object)
785785
}
786786
}
787787

788+
/**
789+
* Check in column value should be quoted
790+
*
791+
* Based on column description
792+
*
793+
* @param array $columnDescription
794+
* @return bool
795+
*/
796+
private function isNeedToQuoteValue(array $columnDescription): bool
797+
{
798+
$result = true;
799+
if (!empty($columnDescription['DATA_TYPE'])
800+
&& in_array($columnDescription['DATA_TYPE'], ['smallint', 'int'])) {
801+
$result = false;
802+
}
803+
return $result;
804+
}
805+
788806
/**
789807
* Update existing object
790808
*
@@ -798,7 +816,9 @@ protected function updateObject(\Magento\Framework\Model\AbstractModel $object)
798816
$connection = $this->getConnection();
799817
$tableDescription = $connection->describeTable($this->getMainTable());
800818
$preparedValue = $connection->prepareColumnValue($tableDescription[$this->getIdFieldName()], $object->getId());
801-
$condition = $this->getIdFieldName() . '=' . $preparedValue;
819+
$condition = (!$this->isNeedToQuoteValue($tableDescription[$this->getIdFieldName()]))
820+
? $this->getIdFieldName() . '=' . $preparedValue
821+
: $connection->quoteInto($this->getIdFieldName() . '=?', $preparedValue);
802822

803823
/**
804824
* Not auto increment primary key support

lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/Db/AbstractDbTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ public function testPrepareDataForUpdate()
496496
->with(
497497
'tableName',
498498
$newData,
499-
'idFieldName=0'
499+
'idFieldName'
500500
);
501501
$select = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
502502
->disableOriginalConstructor()

0 commit comments

Comments
 (0)