Skip to content

Commit

Permalink
Merge pull request #10196 from silverstripe-terraformers/bugfix/grid-…
Browse files Browse the repository at this point in the history
…field-export-button

ENH Improve gridfield export pefromance by using DataList generator
  • Loading branch information
michalkleiner authored Jan 11, 2022
2 parents acb04e3 + 048eb4b commit 945a506
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Forms/GridField/GridFieldExportButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;

/**
Expand Down Expand Up @@ -220,8 +221,15 @@ public function generateExportFileData($gridField)
? $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 = [];

Expand Down

0 comments on commit 945a506

Please sign in to comment.