Since I had similar or maybe the exactly the same issue today I wanted to post solution:
In my case I had configurable attribute with maybe 20k options.
Product Detail Page took forever to load.
After some research I found other ppl also had similar issue:
Link 1
Link 2
Solution was the following:
I copied:
/app/code/core/Mage/ConfigurableSwatches/Model/Resource/Catalog/Product/Attribute/Super/Collection.php
to local:
/app/code/local/Mage/ConfigurableSwatches/Model/Resource/Catalog/Product/Attribute/Super/Collection.php
(Please note you should change: $fallbackStoreId variable)
and made following change to speed up the things:
protected function _loadOptionLabels()
{
if ($this->count()) {
$labels = $this->_getOptionLabels();
foreach ($this->getItems() as $item) {
$item->setOptionLabels($labels);
}
}
return $this;
}
protected function _getOptionLabels()
{
$attributeIds = $this->_getAttributeIds();
$fallbackStoreId = 2;
$select = $this->getConnection()->select();
$select->from(array('options' => $this->getTable('eav/attribute_option')))
->join(
array('labels' => $this->getTable('eav/attribute_option_value')),
'labels.option_id = options.option_id',
array(
'label' => 'labels.value',
'store_id' => 'labels.store_id',
)
)
->where('options.attribute_id IN (?)', $attributeIds)
->where(
'labels.store_id IN (?)',
array($fallbackStoreId, $this->getStoreId())
);
$labels = array();
$thisClass = $this;
Mage::getSingleton('core/resource_iterator')->walk(
$select,
array(function($args) use (&$thisClass){
$data = $args['row'];
$labels[$data['option_id']][$data['store_id']] = $data['label'];
})
);
return $labels;
}
protected function _getAttributeIds()
{
$attributeIds = array();
foreach ($this->getItems() as $item) {
$attributeIds[] = $item->getAttributeId();
}
$attributeIds = array_unique($attributeIds);
return $attributeIds;
}