Skip to content

Commit 83a3ccc

Browse files
committed
MAGETWO-97411: \Magento\Customer\Model\Customer::getDataModel method takes to much time to load with many addresses customer
1 parent 4a05eca commit 83a3ccc

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

app/code/Magento/Customer/Model/Customer.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ class Customer extends \Magento\Framework\Model\AbstractModel
220220
private $accountConfirmation;
221221

222222
/**
223-
* Caching property to store customer addresses by the customer ID.
223+
* Caching property to store customer address data models by the address ID.
224224
*
225225
* @var array
226226
*/
@@ -319,14 +319,12 @@ public function getDataModel()
319319
{
320320
$customerData = $this->getData();
321321
$addressesData = [];
322-
if (isset($customerData['entity_id']) && !isset($this->storedAddress[$customerData['entity_id']])) {
323-
/** @var \Magento\Customer\Model\Address $address */
324-
foreach ($this->getAddresses() as $address) {
325-
$addressesData[] = $address->getDataModel();
322+
/** @var \Magento\Customer\Model\Address $address */
323+
foreach ($this->getAddresses() as $address) {
324+
if (!isset($this->storedAddress[$address->getId()])) {
325+
$this->storedAddress[$address->getId()] = $address->getDataModel();
326326
}
327-
$this->storedAddress[$customerData['entity_id']] = $addressesData;
328-
} elseif (isset($customerData['entity_id'], $this->storedAddress[$customerData['entity_id']])) {
329-
$addressesData = $this->storedAddress[$customerData['entity_id']];
327+
$addressesData[] = $this->storedAddress[$address->getId()];
330328
}
331329
$customerDataObject = $this->customerDataFactory->create();
332330
$this->dataObjectHelper->populateWithArray(

app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
/**
2020
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
21+
* @SuppressWarnings(PHPMD.TooManyFields)
2122
*/
2223
class CustomerTest extends \PHPUnit\Framework\TestCase
2324
{

0 commit comments

Comments
 (0)