Custom export takes too long
Opened this issue · 2 comments
Hi @f3l1x, @paveljanda,
Is possible to change method getDataSource() in file Contributte\Datagrid\DataSource\NextrasDataSource.php here visibility from protected to public?
In my case I am doing custom export, because included CSV export takes too long in case large model dependences, so I prepared custom SQL query and now i need to pass argument $userIds, which I get from filtered items from datagrid. For now there is no accessable method to get collection, here is only method getData(), but it returns Nextras Model fetchAll(), that i later iterating for get array of filtered ids. Which also takes too long. Best way for me is public visibility method getDataSource(), where I can call fetchPairs(null, 'id').
Thanx
Seems to me like you are exporting all data and then want to filter them by filtered rows from grid.
Wouldn't be method $grid->addExportCsvFiltered()
a solution?
See docs.
Not exactly. I used to use $grid->addExportCsvFiltered(), but there is same problem with fetching all amount of data and model dependecies such as relationships, virtual properities, etc.
If I use addExportCsvFiltered, it creates new object ExportCsv, which contains public method isFiltered(), that method is called in DataGrid.php at method handleExport. That assembly the filters and set them in DataModel.php, which returns method getData() or here. Here comes the problem with calling getData() method, because it fire fetchAll method, but this is the problematic part which make my export slow. The solution is make accessible method getDataSource(), because DataGrid makes the whole ICollection updated, based on ordering or filtering via DateTimeFilters or TextFilters or any other supported types of filters. So, if I getData(), which contains array of Entity I need to make iteration, where i collect ids to other property. But if can access getDataSource of the current Datagrid datasource (in my case NextrasDataSource), it returns in my case the ICollection object. Then I can call fetchPairs(null, 'id'), which can get me array of integers (Entity IDs), later I pass them to my SQL query, which returns me exact items as I can get from addExportCsvFiltered(), but with one important difference. Now export won't take 3 minutes, but 3 seconds. I tried this locally by modifying it in vendor. I have large database with amount of dependencies on other Entities, which are slower down whole ORM and whole process.