Skip to content

Instantly share code, notes, and snippets.

@manelio
Created November 12, 2014 11:40
Show Gist options
  • Select an option

  • Save manelio/5791101c513bf2d5d531 to your computer and use it in GitHub Desktop.

Select an option

Save manelio/5791101c513bf2d5d531 to your computer and use it in GitHub Desktop.
Magento performance: getSortedAttributes caching
Core optimization I:
Test:
url: http://myproject.com.local/ (a catalog page that loads 111 products)
Before:
Total Incl. Wall Time (microsec): 34,340,233 microsecs
Number of Function Calls: 10,098,542
After:
Total Incl. Wall Time (microsec): 16,672,205 microsecs
Number of Function Calls: 3,944,652
Code:
# create a copy of Mage_Eav_Model_Entity_Abstract in pool local
install -D web/app/code/core/Mage/Eav/Model/Entity/Abstract.php web/app/code/local/Mage/Eav/Model/Entity/Abstract.php
# add to class attributes:
protected static $_sortedAttributesBySetId = array();
# rename method getSortedAttributes to _getSortedAttributes
# add method getSortedAttributes:
public function getSortedAttributes($setId = null)
{
if (key_exists($setId, self::$_sortedAttributesBySetId)) {
$sortedAttributes = self::$_sortedAttributesBySetId[ $setId ];
}
else {
$sortedAttributes = $this->_getSortedAttributes($setId);
self::$_sortedAttributesBySetId[ $setId ] = $sortedAttributes;
}
return $sortedAttributes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment