Adding a product to the cart takes just over a minute even though I have a very decent server. On closer inspection, the customer/section/load/ request is taking over a minute to load.
Debugging it showed the Magento\Checkout\CustomerData\DirectoryData section that's slow loading whilst the other sections like cart, messages, jsdatalayer, load extremely quick.
This is the code that slow:
/**
* {@inheritdoc}
*/
public function getSectionData()
{
$output = [];
$regionsData = $this->directoryHelper->getRegionData();
/**
* @var string $code
* @var \Magento\Directory\Model\Country $data
*/
foreach ($this->directoryHelper->getCountryCollection() as $code => $data) {
$output[$code]['name'] = $data->getName();
if (array_key_exists($code, $regionsData)) {
foreach ($regionsData[$code] as $key => $region) {
$output[$code]['regions'][$key]['code'] = $region['code'];
$output[$code]['regions'][$key]['name'] = $region['name'];
}
}
}
return $output;
}
As as a quick dirty test I added a return statement just before the $this->directoryHelper->getRegionData(); which made the add to cart action complete in about 1.15s as opposed to over 1 minute.
How can this function be optimized?
Thanks.