Our Magento installation has a home page block which displays a random selection of products from a given category. It works, but it's really slow. I tracked the culprit down to the following function:
protected function _getProductCollection()
$categoryID = $this->getCategoryId();
$category = new Mage_Catalog_Model_Category();
$collection = $category->getProductCollection();
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->getSelect()->order('rand()'); // REALLY slow, approx 4000ms at 25k products
$productCount = $this->getProductCount() ? $this->getProductCount() : 8;
$this->_productCollection = $collection;
Specifically, it is the $collection->getSelect()->order('rand()'); statement that is extremely slow, adding around 4000ms to our time to first byte at our current product count of ~25k. Simply disabling randomness shaves about 3700ms off our page load time.
I would like to perform the randomization at application level, rather than use the notoriously slow MySQL ORDER BY RAND() method. Specifically, I would like you to implement the method described here: [url removed, login to view]
The deliverable is the updated _getProductCollection() function pasted above, modified to use an application level randomization method. The suggested solution is one, but you're free to use any method you choose, as long as it works and it's fast.
7 freelancers estão ofertando em média $38 para este trabalho
Hi, That is a simple task. With my 5 years magento development I would love to do more for you in the future issues if you have. Please contact me via skype ndthan25 and I will change it for you. Regards,