diff --git a/vendor/magento/module-catalog-inventory/Model/ResourceModel/Stock.php b/vendor/magento/module-catalog-inventory/Model/ResourceModel/Stock.php index eaea6ee560c..0a674c01365 100644 --- a/vendor/magento/module-catalog-inventory/Model/ResourceModel/Stock.php +++ b/vendor/magento/module-catalog-inventory/Model/ResourceModel/Stock.php @@ -125,10 +125,19 @@ class Stock extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb impleme return []; } $itemTable = $this->getTable('cataloginventory_stock_item'); - $select = $this->getConnection()->select()->from(['si' => $itemTable]) + + //get indexed entries for row level lock instead of table lock + $itemIds = []; + $preSelect = $this->getConnection()->select()->from($itemTable, 'item_id') ->where('website_id = ?', $websiteId) - ->where('product_id IN(?)', $productIds) - ->forUpdate(true); + ->where('product_id IN(?)', $productIds); + foreach ($this->getConnection()->query($preSelect)->fetchAll() as $item) { + $itemIds[] = $item['item_id']; + } + + $select = $this->getConnection()->select()->from(['si' => $itemTable]) + ->where('item_id IN (?)', $itemIds); + $selectString = (string)$select . ' LOCK IN SHARE MODE'; $productTable = $this->getTable('catalog_product_entity'); $selectProducts = $this->getConnection()->select()->from(['p' => $productTable], []) @@ -141,18 +150,17 @@ class Stock extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb impleme ); $items = []; - foreach ($this->getConnection()->query($select)->fetchAll() as $si) { + foreach ($this->getConnection()->query($selectString)->fetchAll() as $si) { $items[$si['product_id']] = $si; } foreach ($this->getConnection()->fetchAll($selectProducts) as $p) { $items[$p['product_id']]['type_id'] = $p['type_id']; } - return $items; } /** - * {@inheritdoc} + * @inheritdoc */ public function correctItemsQty(array $items, $websiteId, $operator) { @@ -161,18 +169,13 @@ class Stock extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb impleme } $connection = $this->getConnection(); - $conditions = []; + $itemTable = $this->getTable('cataloginventory_stock_item'); + $connection->beginTransaction(); foreach ($items as $productId => $qty) { - $case = $connection->quoteInto('?', $productId); - $result = $connection->quoteInto("qty{$operator}?", $qty); - $conditions[$case] = $result; + $value = new \Zend_Db_Expr($connection->quoteInto("qty{$operator}?", $qty)); + $where = ['website_id = ?' => $websiteId, 'product_id = ?' => $productId]; + $connection->update($itemTable, ['qty' => $value], $where); } - - $value = $connection->getCaseSql('product_id', $conditions, 'qty'); - $where = ['product_id IN (?)' => array_keys($items), 'website_id = ?' => $websiteId]; - - $connection->beginTransaction(); - $connection->update($this->getTable('cataloginventory_stock_item'), ['qty' => $value], $where); $connection->commit(); } diff --git a/vendor/magento/module-catalog-inventory/etc/db_schema.xml b/vendor/magento/module-catalog-inventory/etc/db_schema.xml index 67a200eb371..21ef3aa4c46 100644 --- a/vendor/magento/module-catalog-inventory/etc/db_schema.xml +++ b/vendor/magento/module-catalog-inventory/etc/db_schema.xml @@ -87,6 +87,10 @@ + + + + diff --git a/vendor/magento/module-catalog-inventory/etc/db_schema_whitelist.json b/vendor/magento/module-catalog-inventory/etc/db_schema_whitelist.json index 2580ec1e336..fd881ac6e52 100644 --- a/vendor/magento/module-catalog-inventory/etc/db_schema_whitelist.json +++ b/vendor/magento/module-catalog-inventory/etc/db_schema_whitelist.json @@ -43,6 +43,7 @@ }, "index": { "CATALOGINVENTORY_STOCK_ITEM_WEBSITE_ID": true, + "CATALOGINVENTORY_STOCK_ITEM_WEBSITE_ID_PRODUCT_ID": true, "CATALOGINVENTORY_STOCK_ITEM_STOCK_ID": true }, "constraint": { @@ -123,4 +124,4 @@ "PRIMARY": true } } -} \ No newline at end of file +} diff --git a/vendor/magento/module-customer/etc/db_schema.xml b/vendor/magento/module-customer/etc/db_schema.xml index c699db06d30..b813a17bca9 100644 --- a/vendor/magento/module-customer/etc/db_schema.xml +++ b/vendor/magento/module-customer/etc/db_schema.xml @@ -457,6 +457,9 @@ + + + diff --git a/vendor/magento/module-customer/etc/db_schema_whitelist.json b/vendor/magento/module-customer/etc/db_schema_whitelist.json index ec7a53945ab..f289308916d 100644 --- a/vendor/magento/module-customer/etc/db_schema_whitelist.json +++ b/vendor/magento/module-customer/etc/db_schema_whitelist.json @@ -284,6 +284,9 @@ "is_filterable_in_grid": true, "is_searchable_in_grid": true }, + "index": { + "CUSTOMER_EAV_ATTRIBUTE_SORT_ORDER": true + }, "constraint": { "PRIMARY": true, "CUSTOMER_EAV_ATTRIBUTE_ATTRIBUTE_ID_EAV_ATTRIBUTE_ATTRIBUTE_ID": true diff --git a/vendor/magento/module-eav/Model/ResourceModel/Entity/Attribute.php b/vendor/magento/module-eav/Model/ResourceModel/Entity/Attribute.php index 2a1b8600f83..58b07bd63fe 100644 --- a/vendor/magento/module-eav/Model/ResourceModel/Entity/Attribute.php +++ b/vendor/magento/module-eav/Model/ResourceModel/Entity/Attribute.php @@ -101,7 +101,7 @@ class Attribute extends AbstractDb */ public function loadByCode(AbstractModel $object, $entityTypeId, $code) { - $bind = [':entity_type_id' => $entityTypeId]; + $bind = [':entity_type_id' => (int)$entityTypeId]; $select = $this->_getLoadSelect('attribute_code', $code, $object)->where('entity_type_id = :entity_type_id'); $data = $this->getConnection()->fetchRow($select, $bind); @@ -297,7 +297,7 @@ class Attribute extends AbstractDb if ($additionalTable) { $connection = $this->getConnection(); $data = $this->_prepareDataForTable($object, $this->getTable($additionalTable)); - $bind = [':attribute_id' => $object->getId()]; + $bind = [':attribute_id' => (int)$object->getId()]; $select = $connection->select()->from( $this->getTable($additionalTable), ['attribute_id'] diff --git a/vendor/magento/module-eav/etc/db_schema.xml b/vendor/magento/module-eav/etc/db_schema.xml index b6c42d725e5..ed5c975fb50 100644 --- a/vendor/magento/module-eav/etc/db_schema.xml +++ b/vendor/magento/module-eav/etc/db_schema.xml @@ -305,6 +305,11 @@ + + + + +