mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-05-07 07:17:43 -04:00
Improve get_found_rows query performance (#1940)
This commit is contained in:
@@ -354,17 +354,15 @@ class Customer extends Person
|
||||
{
|
||||
return $this->db->get()->row_array()['count'];
|
||||
}
|
||||
else
|
||||
|
||||
$this->db->order_by($sort, $order);
|
||||
|
||||
if($rows > 0)
|
||||
{
|
||||
$this->db->order_by($sort, $order);
|
||||
|
||||
if($rows > 0)
|
||||
{
|
||||
$this->db->limit($rows, $limit_from);
|
||||
}
|
||||
|
||||
return $this->db->get();
|
||||
$this->db->limit($rows, $limit_from);
|
||||
}
|
||||
|
||||
return $this->db->get();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -290,17 +290,15 @@ class Employee extends Person
|
||||
{
|
||||
return $this->db->get()->row_array()['count'];
|
||||
}
|
||||
else
|
||||
|
||||
$this->db->order_by($sort, $order);
|
||||
|
||||
if($rows > 0)
|
||||
{
|
||||
$this->db->order_by($sort, $order);
|
||||
|
||||
if($rows > 0)
|
||||
{
|
||||
$this->db->limit($rows, $limit_from);
|
||||
}
|
||||
|
||||
return $this->db->get();
|
||||
$this->db->limit($rows, $limit_from);
|
||||
}
|
||||
|
||||
return $this->db->get();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -64,7 +64,7 @@ class Expense extends CI_Model
|
||||
// get_found_rows case
|
||||
if($count_only == TRUE)
|
||||
{
|
||||
$this->db->select('COUNT(expenses.expense_id) as count');
|
||||
$this->db->select('COUNT(DISTINCT expenses.expense_id) as count');
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -136,24 +136,22 @@ class Expense extends CI_Model
|
||||
$this->db->like('expenses.payment_type', $this->lang->line('expenses_check'));
|
||||
}
|
||||
|
||||
$this->db->group_by('expense_id');
|
||||
|
||||
// get_found_rows case
|
||||
if($count_only == TRUE)
|
||||
{
|
||||
return $this->db->get()->row_array()['count'];
|
||||
}
|
||||
else
|
||||
|
||||
$this->db->group_by('expense_id');
|
||||
|
||||
$this->db->order_by($sort, $order);
|
||||
|
||||
if($rows > 0)
|
||||
{
|
||||
$this->db->order_by($sort, $order);
|
||||
|
||||
if($rows > 0)
|
||||
{
|
||||
$this->db->limit($rows, $limit_from);
|
||||
}
|
||||
|
||||
return $this->db->get();
|
||||
$this->db->limit($rows, $limit_from);
|
||||
}
|
||||
|
||||
return $this->db->get();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -153,17 +153,15 @@ class Expense_category extends CI_Model
|
||||
{
|
||||
return $this->db->get()->row_array()['count'];
|
||||
}
|
||||
else
|
||||
|
||||
$this->db->order_by($sort, $order);
|
||||
|
||||
if($rows > 0)
|
||||
{
|
||||
$this->db->order_by($sort, $order);
|
||||
|
||||
if($rows > 0)
|
||||
{
|
||||
$this->db->limit($rows, $limit_from);
|
||||
}
|
||||
|
||||
return $this->db->get();
|
||||
$this->db->limit($rows, $limit_from);
|
||||
}
|
||||
|
||||
return $this->db->get();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -233,17 +233,15 @@ class Giftcard extends CI_Model
|
||||
{
|
||||
return $this->db->get()->row_array()['count'];
|
||||
}
|
||||
else
|
||||
|
||||
$this->db->order_by($sort, $order);
|
||||
|
||||
if($rows > 0)
|
||||
{
|
||||
$this->db->order_by($sort, $order);
|
||||
|
||||
if($rows > 0)
|
||||
{
|
||||
$this->db->limit($rows, $limit_from);
|
||||
}
|
||||
|
||||
return $this->db->get();
|
||||
$this->db->limit($rows, $limit_from);
|
||||
}
|
||||
|
||||
return $this->db->get();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -108,7 +108,7 @@ class Item extends CI_Model
|
||||
// get_found_rows case
|
||||
if($count_only == TRUE)
|
||||
{
|
||||
$this->db->select('COUNT(items.item_id) as count');
|
||||
$this->db->select('COUNT(DISTINCT items.item_id) as count');
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -226,26 +226,24 @@ class Item extends CI_Model
|
||||
$this->db->where('items.description', '');
|
||||
}
|
||||
|
||||
// avoid duplicated entries with same name because of inventory reporting multiple changes on the same item in the same date range
|
||||
$this->db->group_by('items.item_id');
|
||||
|
||||
// get_found_rows case
|
||||
if($count_only == TRUE)
|
||||
{
|
||||
return $this->db->get()->row_array()['count'];
|
||||
}
|
||||
else
|
||||
|
||||
// avoid duplicated entries with same name because of inventory reporting multiple changes on the same item in the same date range
|
||||
$this->db->group_by('items.item_id');
|
||||
|
||||
// order by name of item by default
|
||||
$this->db->order_by($sort, $order);
|
||||
|
||||
if($rows > 0)
|
||||
{
|
||||
// order by name of item by default
|
||||
$this->db->order_by($sort, $order);
|
||||
|
||||
if($rows > 0)
|
||||
{
|
||||
$this->db->limit($rows, $limit_from);
|
||||
}
|
||||
|
||||
return $this->db->get();
|
||||
$this->db->limit($rows, $limit_from);
|
||||
}
|
||||
|
||||
return $this->db->get();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -233,17 +233,15 @@ class Item_kit extends CI_Model
|
||||
{
|
||||
return $this->db->get()->row_array()['count'];
|
||||
}
|
||||
else
|
||||
|
||||
$this->db->order_by($sort, $order);
|
||||
|
||||
if($rows > 0)
|
||||
{
|
||||
$this->db->order_by($sort, $order);
|
||||
|
||||
if($rows > 0)
|
||||
{
|
||||
$this->db->limit($rows, $limit_from);
|
||||
}
|
||||
|
||||
return $this->db->get();
|
||||
$this->db->limit($rows, $limit_from);
|
||||
}
|
||||
|
||||
return $this->db->get();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -188,7 +188,7 @@ class Sale extends CI_Model
|
||||
// get_found_rows case
|
||||
if($count_only == TRUE)
|
||||
{
|
||||
$this->db->select('COUNT(sales.sale_id) as count');
|
||||
$this->db->select('COUNT(DISTINCT sales.sale_id) as count');
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -276,25 +276,23 @@ class Sale extends CI_Model
|
||||
$this->db->like('payments.payment_type', $this->lang->line('sales_check'));
|
||||
}
|
||||
|
||||
$this->db->group_by('sales.sale_id');
|
||||
|
||||
// get_found_rows case
|
||||
if($count_only == TRUE)
|
||||
{
|
||||
return $this->db->get()->row_array()['count'];
|
||||
}
|
||||
else
|
||||
|
||||
$this->db->group_by('sales.sale_id');
|
||||
|
||||
// order by sale time by default
|
||||
$this->db->order_by($sort, $order);
|
||||
|
||||
if($rows > 0)
|
||||
{
|
||||
// order by sale time by default
|
||||
$this->db->order_by($sort, $order);
|
||||
|
||||
if($rows > 0)
|
||||
{
|
||||
$this->db->limit($rows, $limit_from);
|
||||
}
|
||||
|
||||
return $this->db->get();
|
||||
$this->db->limit($rows, $limit_from);
|
||||
}
|
||||
|
||||
return $this->db->get();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -263,17 +263,15 @@ class Supplier extends Person
|
||||
{
|
||||
return $this->db->get()->row_array()['count'];
|
||||
}
|
||||
else
|
||||
|
||||
$this->db->order_by($sort, $order);
|
||||
|
||||
if($rows > 0)
|
||||
{
|
||||
$this->db->order_by($sort, $order);
|
||||
|
||||
if($rows > 0)
|
||||
{
|
||||
$this->db->limit($rows, $limit_from);
|
||||
}
|
||||
|
||||
return $this->db->get();
|
||||
$this->db->limit($rows, $limit_from);
|
||||
}
|
||||
|
||||
return $this->db->get();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -295,19 +295,40 @@ class Tax extends CI_Model
|
||||
return $this->db->delete('tax_code_rates');
|
||||
}
|
||||
|
||||
/**
|
||||
Gets tax_codes
|
||||
*/
|
||||
public function get_found_rows($search)
|
||||
{
|
||||
return $this->search($search, 0, 0, 'tax_code', 'asc', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
Performs a search on tax_codes
|
||||
*/
|
||||
public function search($search, $rows = 0, $limit_from = 0, $sort = 'tax_code', $order = 'asc')
|
||||
public function search($search, $rows = 0, $limit_from = 0, $sort = 'tax_code', $order = 'asc', $count_only = FALSE)
|
||||
{
|
||||
// get_found_rows case
|
||||
if($count_only == TRUE)
|
||||
{
|
||||
$this->db->select('COUNT(tax_code) as count');
|
||||
}
|
||||
|
||||
$this->db->from('tax_codes');
|
||||
$this->db->join('tax_code_rates',
|
||||
'tax_code = rate_tax_code and rate_tax_category_id = 1', 'LEFT');
|
||||
if (!empty($search))
|
||||
$this->db->join('tax_code_rates', 'tax_code = rate_tax_code AND rate_tax_category_id = 1', 'LEFT');
|
||||
|
||||
if(!empty($search))
|
||||
{
|
||||
$this->db->like('tax_code', $search);
|
||||
$this->db->or_like('tax_code_name', $search);
|
||||
}
|
||||
|
||||
// get_found_rows case
|
||||
if($count_only == TRUE)
|
||||
{
|
||||
return $this->db->get()->row_array()['count'];
|
||||
}
|
||||
|
||||
$this->db->order_by($sort, $order);
|
||||
|
||||
if($rows > 0)
|
||||
@@ -318,21 +339,6 @@ class Tax extends CI_Model
|
||||
return $this->db->get();
|
||||
}
|
||||
|
||||
/**
|
||||
Gets tax_codes
|
||||
*/
|
||||
public function get_found_rows($search)
|
||||
{
|
||||
$this->db->from('tax_codes');
|
||||
if (!empty($search))
|
||||
{
|
||||
$this->db->like('tax_code', $search);
|
||||
$this->db->or_like('tax_code_name', $search);
|
||||
}
|
||||
|
||||
return $this->db->get()->num_rows();
|
||||
}
|
||||
|
||||
public function get_tax_code_type_name($tax_code_type)
|
||||
{
|
||||
if ($tax_code_type == '0')
|
||||
|
||||
Reference in New Issue
Block a user