Topic: Some changes in add_supp_invoice to reduce unnecessary query run time
As i have seen some queries which unnecesaarily runs within loops or its called multiple times to pass it to another data. There is one recent one I am bring here to update the core makes simple.
/purchasing/includes/db/invoice_db.inc
From the add_supp_invoice function, there is items line foreach which has a function inside it
$currency = get_supplier_currency($supp_trans->supplier_id);
This actually no point to run within items loop, just imagine, if the user add 50 items in one invoice and tries to save. this query runs 49 times unnecessarily. and also one more thing with the same function.
From this function
function add_gl_trans_supplier($type, $type_no, $date_, $account, $dimension, $dimension2,
$amount, $supplier_id, $err_msg="", $rate=0, $memo="")
{
if ($err_msg == "")
$err_msg = "The supplier GL transaction could not be inserted";
return add_gl_trans($type, $type_no, $date_, $account, $dimension, $dimension2, $memo,
$amount, get_supplier_currency($supplier_id),
PT_SUPPLIER, $supplier_id, $err_msg, $rate);
}
This is acutally calls more than once for a single item. during the same invoice process. here looks this code.
get_supplier_currency($supplier_id),
it runs more than 100 times as of my above example. So its better take out this and pass one more parameter in the
add_gl_trans_supplier
like this
add_gl_trans_supplier($type, $type_no, $date_, $account, $dimension, $dimension2,
$amount, $supplier_id, $err_msg="", $rate=0, $memo="", $currency=null){
if ($err_msg == "")
$err_msg = "The supplier GL transaction could not be inserted";
if($currency == null )
$currrency = get_supplier_currency($supplier_id);
return add_gl_trans($type, $type_no, $date_, $account, $dimension, $dimension2, $memo,
$amount, $currency,
PT_SUPPLIER, $supplier_id, $err_msg, $rate);
}
. This will simplify more than 150 query load to server when we submit 50 items invoice.
@Joe,And @Janusz, Hope you guys get the point.
HRM CRM POS batch Themes