Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eav config cache followup for multi scope load #3044

Merged
merged 10 commits into from
Mar 9, 2023
Merged
4 changes: 2 additions & 2 deletions app/code/core/Mage/Eav/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ protected function _loadEntityTypes()
protected function _loadEntityAttributes($entityType, $storeId)
{
// preload attributes in array form to avoid instantiating models for every attribute even if it is never accessed
$entityAttributes = $entityType->getAttributeCollection()
$entityAttributes = $entityType->newAttributeCollection()
->addStoreLabel($storeId)
->getData();

Expand All @@ -221,7 +221,7 @@ protected function _loadEntityAttributes($entityType, $storeId)
$attributeId = $entityAttributeData['attribute_id'];
$attributeCode = $entityAttributeData['attribute_code'];

// workaround for getAttributeCollection()->getData() returning all columns as string
// workaround for newAttributeCollection()->getData() returning all columns as string
foreach (self::NUMERIC_ATTRIBUTE_COLUMNS as $key) {
if (!isset($entityAttributeData[$key])) {
continue;
Expand Down
43 changes: 30 additions & 13 deletions app/code/core/Mage/Eav/Model/Entity/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,41 @@ public function loadByCode($code)
/**
* Retrieve entity type attributes collection
*
* @param int $setId
* @return Mage_Eav_Model_Resource_Entity_Attribute_Collection
* @param int|null $setId
* @return Mage_Eav_Model_Resource_Entity_Attribute_Collection
*/
public function getAttributeCollection($setId = null)
{
if ($setId === null && $this->_attributes !== null) {
return $this->_attributes;
} elseif (isset($this->_attributesBySet[$setId])) {
return $this->_attributesBySet[$setId];
}

$collection = $this->newAttributeCollection($setId);

if ($setId === null) {
if ($this->_attributes === null) {
$this->_attributes = $this->_getAttributeCollection()
->setEntityTypeFilter($this);
}
$collection = $this->_attributes;
$this->_attributes = $collection;
} else {
if (!isset($this->_attributesBySet[$setId])) {
$this->_attributesBySet[$setId] = $this->_getAttributeCollection()
->setEntityTypeFilter($this)
->setAttributeSetFilter($setId);
}
$collection = $this->_attributesBySet[$setId];
$this->_attributesBySet[$setId] = $collection;
}

return $collection;
}

/**
* Create entity type attributes collection
*
* @param int|null $setId
* @return Mage_Eav_Model_Resource_Entity_Attribute_Collection
*/
public function newAttributeCollection($setId = null)
{
$collection = $this->_getAttributeCollection()
->setEntityTypeFilter($this);

if ($setId !== null) {
$collection->setAttributeSetFilter($setId);
}

return $collection;
Expand Down