0

Hello i'm new use codeigniter. I have controller like this:

public function index() {
        $data=array('title'     =>'Furniture Design For Small Space',
                    'deskripsi' => 'Decorating Ideas Pictures',
                    'robot'     => 'index,follow',
                    'berita'    => $this->berita_model->daftar_berita(),
                    'random_footer'     => $this->berita_model->random_post_footer(),
                    'rel'       => 0,
                    'isi'       =>'home/index_home'
                        );
        $this->load->view('layout/wrapper',$data);
    }

and this model:

    public function daftar_berita() {
            $this->db->select('wpp.ID,user_nicename,post_date,post_title,post_name,hotlink_thumb,hotlink_source,post_parent');
            $this->db->from('wp_posts wpp'); 
            $this->db->join('wp_users wpu', 'wpu.ID=wpp.post_author');
            $this->db->join('wp_aero_hotlink wpa', 'wpa.hotlink_parent=wpp.ID');
            $this->db->where('wpp.post_type','post');
            $this->db->where('wpp.post_status','publish');
            $this->db->group_by('wpp.post_title'); 
            $this->db->order_by('rand()'); 
            $this->db->limit(10); 

            $query = $this->db->get(); 
            if($query->num_rows() != 0)
            {
                return $query->result_array();
            }
            else
            {
                return false;
            }
    }




    public function random_post_footer() {

                    $this->db->select('post_name,post_title');
                    $this->db->from('wp_posts'); 
                    $this->db->where('post_type','attachment');
                    $this->db->where('post_mime_type','image/jpeg');
                    $this->db->order_by('rand()'); 
                    $this->db->limit(20); 

                    $query = $this->db->get(); 
                    if($query->num_rows() != 0)
                    {
                        return $query->result_array();
                    }
                    else
                    {
                        return false;
                    }



            }

in the database i have 50.000 record, but i have problem the page loads very slowly, more than 5 second.

How can i fix it?

In controller i call two model functions

'berita'    => $this->berita_model->daftar_berita(),
'random_footer'     => $this->berita_model->random_post_footer(),

What's wrong? I tried to call one function models, it can load very fast, under 2 seconds.

Gvidas
  • 1,964
  • 2
  • 14
  • 21
Ofri
  • 51
  • 7
  • Performance issue is caused by `order by rand()`, you can try methos suggested in http://stackoverflow.com/questions/1244555/how-can-i-optimize-mysqls-order-by-rand-function – Gvidas May 18 '16 at 05:57
  • i never think if order by rand() make slow, okey i want try another query – Ofri May 18 '16 at 06:06

0 Answers0