A minor code enhancement to reduce database queries:
file: administrator/components/com_virtuemart/helpers/calculationh.php
Replace lines 97-110:
$epoints = array('Marge','Tax','DBTax','DATax');
$this->allrules = array();
foreach($epoints as $entrypoint){
$q = 'SELECT * FROM #__virtuemart_calcs WHERE
`calc_kind`="' . $entrypoint . '"
AND `published`="1"
AND (`virtuemart_vendor_id`="' . $this->productVendorId . '" OR `shared`="1" )
AND ( publish_up = "' . $this->_db->getEscaped($this->_nullDate) . '" OR publish_up <= "' . $this->_db->getEscaped($this->_now) . '" )
AND ( publish_down = "' . $this->_db->getEscaped($this->_nullDate) . '" OR publish_down >= "' . $this->_db->getEscaped($this->_now) . '" ) ';
$this->_db->setQuery($q);
$this->allrules[$entrypoint] = $this->_db->loadAssocList();
}
With:
$epoints = array("'Marge'","'Tax'","'DBTax'","'DATax'");
$this->allrules = array();
$this->allrules['Marge'] = array();
$this->allrules['Tax'] = array();
$this->allrules['DBTax'] = array();
$this->allrules['DATax'] = array();
$q = 'SELECT * FROM #__virtuemart_calcs WHERE
`calc_kind` IN (' . implode(",",$epoints). ' )
AND `published`="1"
AND (`virtuemart_vendor_id`="' . $this->productVendorId . '" OR `shared`="1" )
AND ( publish_up = "' . $this->_db->getEscaped($this->_nullDate) . '" OR publish_up <= "' . $this->_db->getEscaped($this->_now) . '" )
AND ( publish_down = "' . $this->_db->getEscaped($this->_nullDate) . '" OR publish_down >= "' . $this->_db->getEscaped($this->_now) . '" ) ';
$this->_db->setQuery($q);
$allrules = $this->_db->loadAssocList();
foreach ($allrules as $rule){
$this->allrules[$rule["calc_kind"]] = $rule;
}
this saves 3 database queries
Thanks we will use it.
Hmm I am sorry, but this is not working that way. I just tried to implement it, but the sql does not give back an array of arrays. So it only gives back one rule per type. This 3 queries are not the problem, our bottlenecks are others.
Sorry - it may need this instead:
$this->allrules[$rule["calc_kind"]][] = $rule;
Thanks, yes that works