Reputation: 1274
I'm having a huge issue with Yii, as rendering simple things takes over 10 seconds.
For example:
Controller:
public function actionFailed($id=null) {
if(!is_null($id)) $this->_viewcity=$id;
$failed = Delivery::model()->findAll('failed IS NOT NULL AND city_id = '.$this->_viewcity.' ORDER BY id DESC');
$cities = City::model()->findAll('active > 0');
$this->render('failed',array(
'failed'=>$failed,
'cities'=>$cities,
'city'=>City::model()->findByPk($this->_viewcity),
));
}
In the view only
foreach ($failed as $d)
is used.
Query log: http://jsfiddle.net/kwqabmc0/
How can I optimise this? My SQL server is 23ms ping away and the previously mentioned page takes very long to load.
Upvotes: 0
Views: 124
Reputation: 114
You are use lazy loading of Delivery.items
and Delivery.user
in the view.
Try
$failed = Delivery::model()->with('items', 'user')->findAll('failed IS NOT NULL AND city_id = '.$this->_viewcity.' ORDER BY id DESC');
or do not use these relations in the view.
Upvotes: 1