From 19192817861a2faed50ad7aeb8b10dfbcc63ce25 Mon Sep 17 00:00:00 2001 From: Joel Alphonso Date: Thu, 16 Jun 2022 12:29:43 -0400 Subject: [PATCH] perf(export): improve performance of exporter - use LazyCollectionLoader to prevent memory errors when loading when fetching a big collection - deactivate time limit for ExportAction (huge collection exports will probably take more than the default 30 seconds to export) --- src/Charcoal/Admin/Action/Object/ExportAction.php | 2 ++ src/Charcoal/Admin/Service/Exporter.php | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Charcoal/Admin/Action/Object/ExportAction.php b/src/Charcoal/Admin/Action/Object/ExportAction.php index 617ab13412..ed725502e3 100644 --- a/src/Charcoal/Admin/Action/Object/ExportAction.php +++ b/src/Charcoal/Admin/Action/Object/ExportAction.php @@ -52,6 +52,8 @@ class ExportAction extends AdminAction */ public function run(RequestInterface $request, ResponseInterface $response) { + set_time_limit(0); + $failMessage = $this->translator()->translation('Failed to export object(s)'); $errorThrown = strtr($this->translator()->translation('{{ errorMessage }}: {{ errorThrown }}'), [ '{{ errorMessage }}' => $failMessage diff --git a/src/Charcoal/Admin/Service/Exporter.php b/src/Charcoal/Admin/Service/Exporter.php index 8c6e6cb977..f4c7e5ee25 100644 --- a/src/Charcoal/Admin/Service/Exporter.php +++ b/src/Charcoal/Admin/Service/Exporter.php @@ -12,7 +12,7 @@ use League\Csv\Writer; // From 'charcoal-core' -use Charcoal\Loader\CollectionLoader; +use Charcoal\Loader\LazyCollectionLoader; // From 'charcoal-factory' use Charcoal\Factory\FactoryInterface; @@ -185,7 +185,7 @@ public function collection() )); } - $collection = new CollectionLoader([ + $collection = new LazyCollectionLoader([ 'logger' => $this->logger, 'factory' => $this->modelFactory() ]);