Skip to content

Commit

Permalink
Cache all attribute options for display in layered navigation #943 (#942
Browse files Browse the repository at this point in the history
)

* Cache all attribute options for display in layered navigation
This will improve performance by reducing the amount of SQL Queries when fetching all possible attributes to display in the layered navigation

* Use the attribute's own cache tags

Co-authored-by: Ricardo Velhote <ricardo@caretobeauty.com>
  • Loading branch information
rvelhote and rvelhote authored Jun 26, 2020
1 parent aa14d40 commit 19648fd
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,16 @@ public function getAllOptions($withEmpty = true, $defaultValues = false)
$this->_optionsDefault = array();
}
if (!isset($this->_options[$storeId])) {
$idPrefix = 'ATTRIBUTE_OPTIONS_ID_' . $this->getAttribute()->getId();
$tags = array_merge(
array('eav', Mage_Core_Model_Translate::CACHE_TAG),
$this->getAttribute()->getCacheTags()
);
$collection = Mage::getResourceModel('eav/entity_attribute_option_collection')
->setPositionOrder('asc')
->setAttributeFilter($this->getAttribute()->getId())
->setStoreFilter($this->getAttribute()->getStoreId())
->initCache(Mage::app()->getCache(), $idPrefix, $tags)
->load();
$this->_options[$storeId] = $collection->toOptionArray();
$this->_optionsDefault[$storeId] = $collection->toOptionArray('default_value');
Expand Down

0 comments on commit 19648fd

Please sign in to comment.