1

I have a Magento store, with two store views, one for spanish language, and another one for english, so, I have this code:

//setting spanish store view
Mage::app()->getStore()->setId(8);

$time_start = microtime(true); 

$idProduct = Mage::getModel('catalog/product')->getIdBySku('487767');
$product = Mage::getModel('catalog/product')->load($idProduct);
echo $product->getSku() . PHP_EOL;

$time_end = microtime(true);
$execution_time = ($time_end - $time_start);
echo 'Total Execution Time:'.$execution_time.' Seconds'.PHP_EOL;

When I execute that I see this:

Total Execution Time:0.12779498100281 Seconds

But when I choose a different store view:

 //setting english store view
Mage::app()->getStore()->setId(1);

$time_start = microtime(true); 

$idProduct = Mage::getModel('catalog/product')->getIdBySku('487767');
$product = Mage::getModel('catalog/product')->load($idProduct);
echo $product->getSku() . PHP_EOL;

$time_end = microtime(true);
$execution_time = ($time_end - $time_start);
echo 'Total Execution Time:'.$execution_time.' Seconds'.PHP_EOL;

The execution time is huge different:

Total Execution Time:15.901492834091 Seconds

is consuming a lot of memory, any way for track de SQL generated of "load" function or something? Any ideas are welcome.

0

It's usually because the second store have way more products than the first one. But in your case I doubt that's the problem as they seems to be only language store views (they share the same products right ?)

It could be a problem with indexes, you should try enabling long query log to find out by setting $_debug to true in lib/Varien/Db/Adapter/Pdo/Mysql.php and modifying the $_logQueryTime to find excessively long queries. Then you'll have to check the var/debug/pdo_mysql.log file to find out what's going on with the long sql queries.

Recommendation

Try to avoid load() as much as possible. For instance your code can be optimized with the following code and you'll gain a lot of performance:

Mage::app()->getStore()->setId(1);

$time_start = microtime(true); 

$productCol = Mage::getResourceModel('catalog/product_collection')
                  ->addAttributeToFilter('sku', '487767')
                  ->setPageSize(1);
$product = $productsCol->getFirstItem();
echo $product->getSku() . PHP_EOL;

$time_end = microtime(true);
$execution_time = ($time_end - $time_start);
echo 'Total Execution Time:'.$execution_time.' Seconds'.PHP_EOL;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.