1

I am getting a warning as "fetch All can be memory inefficient for large data sets",
When I did MEQP2.
Please anyone can help me to resolve this warning.

I am getting a warning in below line

$expr = $this->zendExprFactory->create(['expression' => 'COUNT(*)']);

$productMappingQry = $connection->select()->from($this->resourceConfig->getTable($tableName), [$expr])->where('store=?', $storeId);

$finalData = $connection->fetchAll($Qry);

Thank you in advance

1

Try to use fetchOne

$expr = $this->zendExprFactory->create(['expression' => 'COUNT(*)']);

$productMappingQry = $connection->select()->from($this->resourceConfig->getTable($tableName), [$expr])->where('store=?', $storeId);

$finalData = $connection->fetchOne($Qry);
0

If there are multiple records, best practise for this situation

$rowSet = $this->_getReadAdapter()->fetchAll($select);
foreach ($rowSet as $row) {
 //process row
}

would be below one since it will fetch the rows one by one and reduce the memory utilization.

$query = $this->_getReadAdapter()->query($select);
while ($row = $query->fetch()) {
 //process row
}

Reference: https://info2.magento.com/rs/magentosoftware/images/Conquer_the_5_Most_Common_Magento_Coding_Issues_to_Optimize_Your_Site_for_Performance.pdf

Cheers!

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.