Skip to content

Commit e18ab4e

Browse files
ENGCOM-8508: Allow to generate big number of customer on galera cluster #30990
- Merge Pull Request #30990 from kandy/magento2:cust_generator - Merged commits: 1. 6e5d886
2 parents 661c15c + 6e5d886 commit e18ab4e

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

setup/src/Magento/Setup/Model/FixtureGenerator/CustomerGenerator.php

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,24 +124,31 @@ private function getCustomerAddressEntityHandler()
124124
*/
125125
private function addDefaultAddresses()
126126
{
127-
$this->getConnection()->query(
128-
sprintf(
129-
'
130-
update `%s` customer
131-
join (
132-
select
133-
parent_id, min(entity_id) as min, max(entity_id) as max
134-
from `%s`
135-
group by parent_id
136-
) customer_address on customer_address.parent_id = customer.entity_id
127+
$batchSize = 10000;
128+
$customerTableName = $this->resourceConnection->getTableName('customer_entity');
129+
$customerAddressTableName = $this->resourceConnection->getTableName('customer_address_entity');
130+
$customerMaxId = $this->getConnection()->fetchOne("select max(entity_id) from `$customerTableName`");
131+
for ($i = 1; $i < $customerMaxId; $i += $batchSize) {
132+
$this->getConnection()->query(
133+
"
134+
update `$customerTableName` customer
135+
join (
136+
select
137+
parent_id, min(entity_id) as min, max(entity_id) as max
138+
from `$customerAddressTableName`
139+
group by parent_id
140+
) customer_address on customer_address.parent_id = customer.entity_id
137141
set
138142
customer.default_billing = customer_address.min,
139143
customer.default_shipping = customer_address.max
140-
',
141-
$this->resourceConnection->getTableName('customer_entity'),
142-
$this->resourceConnection->getTableName('customer_address_entity')
143-
)
144-
);
144+
where entity_id between :min and :max
145+
",
146+
[
147+
'min' => $i,
148+
'max' => $i + $batchSize
149+
]
150+
);
151+
}
145152
}
146153

147154
/**

0 commit comments

Comments
 (0)