Skip to content

Commit ef41f3a

Browse files
committed
MC-31089: [Escalation] [SAQ] - Customer migration is too slow
1 parent e25e509 commit ef41f3a

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

app/code/Magento/CustomerImportExport/Model/Import/Address.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ public function prepareCustomerData($rows): void
475475

476476
$ids = [];
477477
foreach ($customersPresent as $customerData) {
478-
$id = $this->getCustomerStorage()->getCustomerId(
478+
$id = $this->getCustomerStorage()->getLoadedCustomerId(
479479
$customerData['email'],
480480
$customerData['website_id']
481481
);

app/code/Magento/CustomerImportExport/Model/ResourceModel/Import/Customer/Storage.php

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
1010
use Magento\Framework\DataObject;
1111
use Magento\Framework\DB\Select;
12-
use Magento\ImportExport\Model\ResourceModel\CollectionByPagesIterator;
13-
use Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory;
1412

1513
/**
1614
* Storage to check existing customers.
@@ -38,13 +36,6 @@ class Storage
3836
*/
3937
protected $_pageSize;
4038

41-
/**
42-
* Collection by pages iterator.
43-
*
44-
* @var CollectionByPagesIterator
45-
*/
46-
protected $_byPagesIterator;
47-
4839
/**
4940
* @var CustomerCollectionFactory
5041
*/
@@ -71,21 +62,16 @@ class Storage
7162

7263
/**
7364
* @param CustomerCollectionFactory $collectionFactory
74-
* @param CollectionByPagesIteratorFactory $colIteratorFactory
7565
* @param array $data
7666
*/
7767
public function __construct(
7868
CustomerCollectionFactory $collectionFactory,
79-
CollectionByPagesIteratorFactory $colIteratorFactory,
8069
array $data = []
8170
) {
8271
$this->_customerCollection = isset(
8372
$data['customer_collection']
8473
) ? $data['customer_collection'] : $collectionFactory->create();
85-
$this->_pageSize = isset($data['page_size']) ? $data['page_size'] : 0;
86-
$this->_byPagesIterator = isset(
87-
$data['collection_by_pages_iterator']
88-
) ? $data['collection_by_pages_iterator'] : $colIteratorFactory->create();
74+
$this->_pageSize = isset($data['page_size']) ? (int) $data['page_size'] : 0;
8975
$this->customerCollectionFactory = $collectionFactory;
9076
}
9177

@@ -95,21 +81,20 @@ public function __construct(
9581
* @param array $customerIdentifiers With keys "email" and "website_id".
9682
* @return void
9783
*/
98-
private function loadCustomersData(array $customerIdentifiers)
84+
private function loadCustomersData(array $customerIdentifiers): void
9985
{
100-
$this->_pageSize;
101-
10286
/** @var CustomerCollection $collection */
10387
$collection = $this->customerCollectionFactory->create();
10488
$collection->removeAttributeToSelect();
10589
$select = $collection->getSelect();
10690
$customerTableId = array_keys($select->getPart(Select::FROM))[0];
10791

108-
$getChuck = function (int $offset) use ($customerIdentifiers) {
109-
return array_slice($customerIdentifiers, $offset, $this->_pageSize);
92+
$pageSize = $this->_pageSize ?: count($customerIdentifiers);
93+
$getChuck = function (int $offset) use ($customerIdentifiers, $pageSize) {
94+
return array_slice($customerIdentifiers, $offset, $pageSize);
11095
};
11196
$offset = 0;
112-
for ($chunk = $getChuck($offset); !empty($chunk); $offset += $this->_pageSize, $chunk = $getChuck($offset)) {
97+
for ($chunk = $getChuck($offset); !empty($chunk); $offset += $pageSize, $chunk = $getChuck($offset)) {
11398
$emails = array_column($chunk, 'email');
11499
$chunkSelect = clone $select;
115100
$chunkSelect->where($customerTableId . '.email IN (?)', $emails);

0 commit comments

Comments
 (0)