Hi guys!
Me and my fellow is using Yii framework as our tool for development. We started using it last April and as we go along we have learned a lot. But now we are having a problem with retriving data from several tables–it takes too long. Below is an example of how we retrieve data. Can someone help us please in making data retrieval faster?
$criteria=new CDbCriteria();
$criteria->alias = 'Item';
$criteria->distinct = true;
$criteria->join = 'LEFT JOIN newscountry ON Item.ID = newscountry.NEWSITEM_ID
LEFT JOIN newscategory ON Item.ID = newscategory.NEWSITEM_ID
LEFT JOIN category ON newscategory.CATEGORY_ID = category.ID
LEFT JOIN newssubcategory ON Item.ID = newssubcategory.NEWSITEM_ID
LEFT JOIN subcategory ON newssubcategory.SUBCATEGORY_ID = subcategory.ID
LEFT JOIN newssource ON Item.SOURCE_ID = newssource.ID
LEFT JOIN newssubsubcategory ON Item.id = newssubsubcategory.newsitem_id
LEFT JOIN subsubcategory ON newssubsubcategory.subsubcategory_id = subsubcategory.id';
$criteria->condition = '(Item.SOURCE_ID = :sourceid OR :sourceid = "") AND (newscountry.COUNTRY_CODE = :countryCode OR :countryCode = "") AND (newscategory.CATEGORY_ID = :categoryid OR :categoryid = "") AND (Item.STATUS = :status OR :status = "") AND (newssubcategory.SUBCATEGORY_ID = :subcategoryid OR :subcategoryid = "") AND (newssubsubcategory.SUBSUBCATEGORY_ID = :subsubcategoryid OR :subsubcategoryid = "")';
$criteria->params = array(':sourceid'=>$source,':countryCode'=>$countryCode, ':categoryid'=>$category, ':status'=>$status,'subcategoryid'=>$subcategoryid,':subsubcategoryid'=>$subsubcategoryid);
$criteria->order = $order;
$criteria->limit = "2";
$criteria->offset = $offset;
Thanks for anyone who could suggest how would we be able to improve the code. By the way, the tables has an average records/data of 12,000. lol.