Skip to content

Eav config cache followup for multi scope load #3044

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

Merged
merged 10 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 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->getAttributeCollection(null, false)
->addStoreLabel($storeId)
->getData();

Expand Down
4 changes: 4 additions & 0 deletions app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ public function addAttributeToSelect($attribute, $joinType = false)
} else {
$attrInstance = Mage::getSingleton('eav/config')
->getAttribute($this->getEntity()->getType(), $attribute);
// failure to resolve an attribute from the eav config implies it does not exist
if (empty($attrInstance)) {
return $this;
}
}
if (empty($attrInstance)) {
throw Mage::exception(
Expand Down
37 changes: 23 additions & 14 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,33 @@ public function loadByCode($code)
/**
* Retrieve entity type attributes collection
*
* @param int $setId
* @return Mage_Eav_Model_Resource_Entity_Attribute_Collection
* @param int|null $setId
* @param bool $useCache reuse local cache for collection
* @return Mage_Eav_Model_Resource_Entity_Attribute_Collection
*/
public function getAttributeCollection($setId = null)
public function getAttributeCollection($setId = null, $useCache = true)
{
if ($setId === null) {
if ($this->_attributes === null) {
$this->_attributes = $this->_getAttributeCollection()
->setEntityTypeFilter($this);
if ($useCache) {
if ($setId === null && $this->_attributes !== null) {
return $this->_attributes;
} elseif (isset($this->_attributesBySet[$setId])) {
return $this->_attributesBySet[$setId];
}
$collection = $this->_attributes;
} else {
if (!isset($this->_attributesBySet[$setId])) {
$this->_attributesBySet[$setId] = $this->_getAttributeCollection()
->setEntityTypeFilter($this)
->setAttributeSetFilter($setId);
}

$collection = $this->_getAttributeCollection()
->setEntityTypeFilter($this);

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

if ($useCache) {
if ($setId === null) {
$this->_attributes = $collection;
} else {
$this->_attributesBySet[$setId] = $collection;
}
$collection = $this->_attributesBySet[$setId];
}

return $collection;
Expand Down