News:

Looking for documentation? Take a look on our wiki

Main Menu

VM 2 RC3 - small performance tweak

Started by geraint, December 19, 2011, 18:32:50 PM

Previous topic - Next topic

geraint

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

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Milbo

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.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

geraint

Sorry - it may need this instead:
$this->allrules[$rule["calc_kind"]][] = $rule;

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/