mass actions slow with large number of articles
Steps to reproduce
- Install version 2.0.4 of Magento
- Create 15000+ articles
- Select 1 product in the admin product grid
- Choose "Update attributes" from the "Actions" dropdown
Expected result
- Since only one product was selected, the page for updating the attributes should load quickly.
Actual result
- Instead it will take an extraordinary long time (30-90 seconds, depending on the setup) to load the page for updating products.
Root of problem
The problem lies in the Magento\Ui\Component\MassAction\Filter class in the getCollection() method. Here the current search result is obtained and looped over:
foreach ($dataProvider->getSearchResult()->getItems() as $document) {
$ids[] = $document->getId();
}
The problem is that the selected products are not factored into the search result. So, if no active filter is set, the search result will include all products and the method will then loop over all products.
@choukalos performance issue MAGETWO-53360
I still have this issue on Magento 2.1.2.
Moreover, if I have more than 10k items in db when I choose item in massaction and submit, I receive fatal error about memory limit, because Magento tries to load all 10k items from collection. Even if I increase a memory limit, I'm still receiving errors, from Mysql server about "query length limit", because Magento adds all these ids to the collection field filter.
$ids = [];
foreach ($dataProvider->getSearchResult()->getItems() as $document) {
$ids[] = $document->getId();
}
$collection->addFieldToFilter($collection->getIdFieldName(), ['in' => $ids]);
More than that, this error is present not only in product grid, but on all grids which based on UI grid component.
We're tracking a related issue (product mass actions) in MAGETWO-59555 which is closed in mainline. It's possible that issue addresses this problem. Is anyone still seeing this issue in mainline?
As far as I can see, it takes around 10s. I had a look, the fixes from MAGETWO-59555 did not land in 2.1.4
Also running into this using Magento CE 2.1.4.
We use 192M as our memory_limit setting and this issue caused a Allowed memory size to be thrown.
Applying commit https://github.com/magento/magento2/commit/ca93b75416e68d59316144825b5870f22dc30f1e seems to get us around the problem and now we can use Magento again using a memory_limit of 192M.
Would be great if this one could get backported to Magento 2.1.x
Also linking this issue to https://github.com/magento/magento2/issues/7938, since it is a similar problem with the same solution.
@ktruehl thank you for report. The issue has been fixed in MAGETWO-59555 in release 2.2.0