Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom export takes too long #1146

Open
patrikvalentaa opened this issue Sep 3, 2024 · 2 comments
Open

Custom export takes too long #1146

patrikvalentaa opened this issue Sep 3, 2024 · 2 comments

Comments

@patrikvalentaa
Copy link

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

@sasule
Copy link

sasule commented Sep 3, 2024

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.

@patrikvalentaa
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants