⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Is get_total_results correct?



FYildirim
  • profile picture
  • Member

Posted 29 June 2015 - 19:19 PM

I have a table that has 600000 rows. I found that Grocery Grud very slow. I examined the code and I found the slow part on grocery_grud_model.

 

Line 178

  function get_total_results()
    {
    	//set_relation_n_n special queries. We prefer sub queries from a simple join for the relation_n_n as it is faster and more stable on big tables.
    	if(!empty($this->relation_n_n))
    	{
    		$select = "{$this->table_name}.*";
    		$select = $this->relation_n_n_queries($select);

    		$this->db->select($select,false);
    	}

		return $this->db->get($this->table_name)->num_rows();
    }

To get the total count, script gets all result. I changed the code like below.

function get_total_results()
    {
    	//set_relation_n_n special queries. We prefer sub queries from a simple join for the relation_n_n as it is faster and more stable on big tables.
    	if(!empty($this->relation_n_n))
    	{
    		
    		$select = $this->relation_n_n_queries($select);

    	}
	return $this->db->from($this->table_name)->count_all_results();
    }

Performance is good now.