Magento:加载4个产品需要35秒';s
我创建了一个扩展,它根据属性过滤产品集合。 下面是控制器、块和视图模板代码 控制器Magento:加载4个产品需要35秒';s,magento,caching,nginx,Magento,Caching,Nginx,我创建了一个扩展,它根据属性过滤产品集合。 下面是控制器、块和视图模板代码 控制器 $url = Mage::getUrl('no-route'); if(Mage::app()->getRequest()->getParam('ajax')){ echo $this->getLayout()->createBlock('catalogextensions/bestsellers_home_list')
$url = Mage::getUrl('no-route');
if(Mage::app()->getRequest()->getParam('ajax')){
echo $this->getLayout()->createBlock('catalogextensions/bestsellers_home_list')
->setTemplate('catalog/landings/bestseller.phtml')
->toHtml();
}
else{
$this->loadLayout();
$this->getLayout()->getBlock('head')->setTitle('Besesellers');
$this->renderLayout();
}
阻止产品收集功能
$storeId = Mage::app()->getStore()->getId();
$products = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter(array( array( 'attribute'=>'top_seller', 'eq' => '1' )));
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($products);
$products->getSelect()->limit(4,$this->get_cur_page());
return $products ;
产品集合在view.phtml模板上迭代
现在,获得输出需要35秒,下面是我通过使用PHP的microtime()函数获得的执行统计数据
为了
- 30GB内存,带4个vCPU李>
- 应用服务器:Nginx+php5-fpm
- 版本:Magento CE 1.8.0.1
谢谢。您使用了一种有点不推荐的方式来调用过滤器。我不知道这是否真的会影响加载时间,但使用addFieldToFilter()会限制对数据库的调用,并且是有用的。您可以使用:
块可能未正确缓存。我的意思是每次调用页面时都会加载产品。确保您的平面产品设置为打开,并且过滤器所需的所有属性都设置为过滤器 如果一个列表来自EAv表,它可能会消耗大量资源,从而降低速度
另外应用优化技巧。首先,您确定需要添加所有要选择的属性吗? 您可以替换
addAttributeToSelect('*')
与
接下来,那到底是什么
$this->get_cur_page()
做什么?其余的代码不应该造成灾难性的性能问题
PS
这应该是一个评论,但我还不能评论
$this->get_cur_page()