Description
Hello,
I believe i found a misconception in the Tax Model used in the module Weee.
This issue is already there in Magento EE 1.12 and 1.13.
The relevant function is Mage_Weee_Model_Tax::getProductWeeeAttributes, the issue being at line 141 $productAttributes = $product->getTypeInstance()->getSetAttributes($product);
I realized something went wrong due to an unexpected long response time while trying to display my shopping cart when it is starting to be big (> 15 items).
As a reference, my website offers 25k products and approx. 1000 product attributes.
Using Xdebug, i realized that the FTP calcullation and more precisly the aforementionned function was the source of the issue.
Now if we start digging a bit, something really seems off:
-
Line 113: $allWeee = $this->getWeeeTaxAttributeCodes();
We gather all the attributes necessary in order to do the tax calculation. -
Line 141: $productAttributes = $product->getTypeInstance()->getSetAttributes($product);
We gather all the existing attributes and sort them.
When, as it is the case for us, we have 1K attirbutes, sorting them is probably really hungry CPU wise (on top of the DB load to load them prior to that), is that really necessary ?
3)Line 142/143: foreach ($productAttributes as $code => $attribute) { if (in_array($code, $allWeee)) {
We in the end only deal with the Weee attributes.
Therefore, to sum it up:
-
I get the Weee attributes from the DB => Returns 1 attribute
-
I load all the attributes and sort them => 1k results with skyrocketing CPU load while sorting
-
I loop on the 1k attributes for in the end only dealing with one.
-
with a shopping cart containing 20 items, we can multiply this by 20.
My question is the following, why do we need to load and sort all the attributes while we only really need a few ?
Moreover, is sorting them really necessary ?
We already have the necessary attributes code thanks to line 113.
It should be possible to replace line 141 with something like:
$attrCollection = Mage::getModel('eav/entity_attribute') ->getResourceCollection() ->setCodeFilter($allWeee); foreach ($attrCollection as $attr) { $productAttributes[$attr->getAttributeCode()] = $attr; }
While i did not sort the attributes in this specific case, i already saved up 70% of CPU load.
I am currently working on a fix to just load the attributes which are necessary and to keep the sorting, please let me know if you think it's worth it and i will try to provide it.
Best Regards,
Activity