php - CodeIgniter $db query optimization -


i have problem query generated in following method:

function most_visited($hrs=1,$cat_id=null,$limit=20){     $date = strtotime('- '.$hrs.' hours');     $date = date('y-m-d h:i:s',$date);     $this->db->select('count(content_id) otvaranja, title, id, cat_id, date_start,published,komentari,pocount,postatus ');     $this->db->join('news','news.id=stats.content_id','inner');     $this->db->limit($limit);     if($cat_id !== null){         if(is_array($cat_id)){             $this->db->where_in('cat_id',$cat_id);         } else {             $this->db->where('cat_id',$cat_id);         }     }     $this->db->where('date >=',$date);     $this->db->where('content_type','news');     $this->db->having('otvaranja>=',1,false);     $this->db->group_by('content_id');     $this->db->order_by('otvaranja','desc');     return $this->db->get('stats')->result(); } 

it's killing database.

any suggestions on how alter , make faster?


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -

matlab - How to equate a structure array to structure array -