1

I'm getting memory exhaustion error when executing mass action on a model with large amount of records. I'm trying to optimize this by setting an limit on the collection, however it seems that the full collection is loaded before the limit is even set. Here's the code that causes the memory exhaustion:

$collection = $this->filter->getCollection($this->collectionFactory->create())->setPageSize(1)->setCurPage(1);

It's inside mass action's controller execute method.

edit: So I guess Magento\Ui\Component\MassAction::getFilterIds() is at fault as it generates all selected ids inside an array, to later execute sql in statement to filter which model rows need to be used. Not sure if I even can fix it.

2 Answers2

0
$collection = $this->filter->getCollection($this->collectionFactory->create()->setPageSize(1)->setCurPage(1));

move the limitation of the page right after creating the collection.

Philipp Sander
  • 10,139
  • 6
  • 45
  • 78
  • Hey, thanks for the suggestion, I already had tried it, but it still causes the same error. I think that the fault is inside the Magento\Ui\Component\MassAction::getCollection() method, not sure about exact reason yet though. – Janis Gaikens Jan 14 '19 at 13:23
0

So apperently, the issue was inside Magento\Ui\Component\MassAction::getCollection() that is called inside the filter->getCollection() method. The Id retrievieng method has two options - either rely on dataprovider to get the selected ids, which is the optimized option or go trough each item and add it's id to an array. The problem was that we were not using the first option, for which our modules UI component's dataprovider needed to extend Magento\Ui\DataProvider\AbstractDataProvider.