Details
-
Type:
Improvement
-
Status: Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
Description
We can make the following change to Invoices::getNextInvoiceVars() to improve performance without creating a new index
$values = [$inv_start, $inv_increment, $inv_start]; $sub_query->select(['IFNULL(GREATEST(MAX(t1.id_value),?)+?,?)'], false)-> appendValues($values)-> from(['invoices' => 't1'])-> innerJoin('clients', 'clients.id', '=', 't1.client_id', false)-> innerJoin('client_groups', 'client_groups.id', '=', 'clients.client_group_id', false)-> where('client_groups.company_id', '=', Configure::get('Blesta.company_id'))-> where('t1.id_format', '=', $vars['id_format']);
To
$values = [$inv_start, $inv_increment]; $sub_query->select(['IFNULL(t1.id_value, ?) + ?'], false)-> appendValues($values)-> from(['invoices' => 't1'])-> innerJoin('clients', 'clients.id', '=', 't1.client_id', false)-> innerJoin('client_groups', 'client_groups.id', '=', 'clients.client_group_id', false)-> where('client_groups.company_id', '=', Configure::get('Blesta.company_id'))-> where('t1.id_format', '=', $vars['id_format'])-> order(['t1.id_value' => 'DESC'])-> limit(1);