I am currently going through and optimizing our codebase for our custom modules. I am using PHP Codesniffer along with the Magento Coding Standard rules to scan our code.
In many of our files I see a warning like
Model LSD method save() detected in loop
Here is an example of a function containing that error
public function resetmasstatusAction()
{
$invoicesIds = $this->getRequest()->getPost('invoice_ids');
if (!empty($invoicesIds)) {
$invoices = Mage::getResourceModel('sales/order_invoice_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('entity_id', array('in' => $invoicesIds))
->load();
foreach ($invoices as $invoice) :
$invoice->setMas_status('NEW')
->setMas_updated_at(date('Y-m-d H:i:s'))
->save();
endforeach;
}
$this->_redirect('*/sales_invoice/index');
}
How would I go about doing the save operation for all items in a collection such as this one, without having the save()
function in the foreach
loop to improve performance?