Improve get_found_rows query performance (#1940)

This commit is contained in:
FrancescoUK
2018-04-12 22:42:56 +01:00
parent 8dc7855e56
commit 075d4e1aeb
9 changed files with 312 additions and 234 deletions

View File

@@ -259,27 +259,21 @@ class Employee extends Person
*/
public function get_found_rows($search)
{
$this->db->from('employees');
$this->db->join('people', 'employees.person_id = people.person_id');
$this->db->group_start();
$this->db->like('first_name', $search);
$this->db->or_like('last_name', $search);
$this->db->or_like('email', $search);
$this->db->or_like('phone_number', $search);
$this->db->or_like('username', $search);
$this->db->or_like('CONCAT(first_name, " ", last_name)', $search);
$this->db->group_end();
$this->db->where('deleted', 0);
return $this->db->get()->num_rows();
return $this->search($search, 0, 0, 'last_name', 'asc', TRUE);
}
/*
Performs a search on employees
*/
public function search($search, $rows = 0, $limit_from = 0, $sort = 'last_name', $order = 'asc')
public function search($search, $rows = 0, $limit_from = 0, $sort = 'last_name', $order = 'asc', $count_only = FALSE)
{
$this->db->from('employees');
// get_found_rows case
if($count_only == TRUE)
{
$this->db->select('COUNT(employees.person_id) as count');
}
$this->db->from('employees AS employees');
$this->db->join('people', 'employees.person_id = people.person_id');
$this->db->group_start();
$this->db->like('first_name', $search);
@@ -290,14 +284,23 @@ class Employee extends Person
$this->db->or_like('CONCAT(first_name, " ", last_name)', $search);
$this->db->group_end();
$this->db->where('deleted', 0);
$this->db->order_by($sort, $order);
if($rows > 0)
// get_found_rows case
if($count_only == TRUE)
{
$this->db->limit($rows, $limit_from);
return $this->db->get()->row_array()['count'];
}
else
{
$this->db->order_by($sort, $order);
return $this->db->get();
if($rows > 0)
{
$this->db->limit($rows, $limit_from);
}
return $this->db->get();
}
}
/*