Merge pull request #10196 from silverstripe-terraformers/bugfix/grid-field-export-button

ENH Improve gridfield export pefromance by using DataList generator
This commit is contained in:
Michal Kleiner 2022-01-12 07:32:54 +13:00 committed by GitHub
commit 945a506c4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@ use League\Csv\Writer;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
/**
@ -220,8 +221,15 @@ class GridFieldExportButton implements GridField_HTMLProvider, GridField_ActionP
? $gridFieldColumnsComponent->getColumnsHandled($gridField)
: [];
// Remove limit as the list may be paginated, we want the full list for the export
$items = $items->limit(null);
// Use Generator in applicable cases to reduce memory consumption
$items = $items instanceof DataList
? $items->getGenerator()
: $items;
/** @var DataObject $item */
foreach ($items->limit(null) as $item) {
foreach ($items as $item) {
if (!$item->hasMethod('canView') || $item->canView()) {
$columnData = [];