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

Optimized EAV Cache #532

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions app/code/core/Mage/Catalog/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,7 @@ public function canApplyMsrpToProductType($product)
{
if($this->_mapApplyToProductType === null) {
/** @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
$attribute = Mage::getModel('catalog/resource_eav_attribute')
->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'msrp_enabled');
$attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY,'msrp_enabled');
$this->_mapApplyToProductType = $attribute->getApplyTo();
}
return empty($this->_mapApplyToProductType) || in_array($product->getTypeId(), $this->_mapApplyToProductType);
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Catalog/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ public function getSourceOptionId($source, $value)
*/
public function getProductAttributes()
{
if (is_null($this->_productAttributes)) {
$this->_productAttributes = array_keys($this->getAttributesUsedInProductListing());
if (null === $this->_usedInProductListing) {
$this->_usedInProductListing = Mage::getSingleton('eav/config')->getAttributesUsedInProductListing();
}
return $this->_productAttributes;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you not mean to also update the return statement here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between getProductAttributes() and getAttributesUsedInProductListing()?

}
Expand Down
25 changes: 10 additions & 15 deletions app/code/core/Mage/Catalog/Model/Layer.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,24 +214,19 @@ public function getCurrentStore()
*/
public function getFilterableAttributes()
{
// $entity = Mage::getSingleton('eav/config')
// ->getEntityType('catalog_product');

$setIds = $this->_getSetIds();
if (!$setIds) {
if (false === is_array($setIds) || count($setIds) === 0) {
Copy link
Contributor

@joshua-bn joshua-bn Aug 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!is_array($setIds) || !$setIds) {

return array();
}
/** @var $collection Mage_Catalog_Model_Resource_Product_Attribute_Collection */
$collection = Mage::getResourceModel('catalog/product_attribute_collection');
$collection
->setItemObjectClass('catalog/resource_eav_attribute')
->setAttributeSetFilter($setIds)
->addStoreLabel(Mage::app()->getStore()->getId())
->setOrder('position', 'ASC');
$collection = $this->_prepareAttributeCollection($collection);
$collection->load();

return $collection;
/** @var Mage_Eav_Model_Config $eavConfig */
$attributes = Mage::getSingleton('eav/config')->getFilterableProductAttributesUsedInSets($setIds);
usort($attributes, function ($attributeA, $attributeB){
if ((int)$attributeA->getPosition() == (int)$attributeB->getPosition()) {
return 0;
}
return ((int)$attributeA->getPosition() < (int)$attributeB->getPosition()) ? -1 : 1;
});
return $attributes;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ protected function _getLoadGallerySelect(array $productIds, $storeId, $attribute
*/
protected function _getAttributeId() {
if(is_null($this->_attributeId)) {
$attribute = Mage::getModel('eav/entity_attribute')
->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'media_gallery');
$attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'media_gallery');

$this->_attributeId = $attribute->getId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getTierPriceAttribute()
{
$data = $this->getData('tier_price_attribute');
if (is_null($data)) {
$data = Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'tier_price');
$data = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'tier_price');
$this->setData('tier_price_attribute', $data);
}
return $data;
Expand All @@ -75,7 +75,7 @@ public function getPriceAttribute()
{
$data = $this->getData('price_attribute');
if (is_null($data)) {
$data = Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'price');
$data = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'price');
$this->setData('price_attribute', $data);
}
return $data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ public function getPurchasedSeparatelyAttribute()
if (is_null($this->_purchasedSeparatelyAttribute)) {
$_attributeCode = 'links_purchased_separately';

$this->_purchasedSeparatelyAttribute = Mage::getModel('eav/entity_attribute')
->loadByCode(Mage_Catalog_Model_Product::ENTITY, $_attributeCode);
$this->_purchasedSeparatelyAttribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $_attributeCode);
}

return $this->_purchasedSeparatelyAttribute;
Expand Down
Loading