From 4f7e406d0525ab112c5dee3eebf2a6e789f7ba49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20L=C3=B8vgaard?= Date: Wed, 13 Sep 2023 14:50:55 +0200 Subject: [PATCH] Add batch size as a constructor argument --- src/DataProvider/DataProvider.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/DataProvider/DataProvider.php b/src/DataProvider/DataProvider.php index 748bad8..9a8b2fd 100644 --- a/src/DataProvider/DataProvider.php +++ b/src/DataProvider/DataProvider.php @@ -20,8 +20,6 @@ class DataProvider implements DataProviderInterface { - private const BATCH_SIZE = 100; - private BatcherFactoryInterface $batcherFactory; private QueryRebuilderInterface $queryRebuilder; @@ -35,18 +33,22 @@ class DataProvider implements DataProviderInterface /** @var CollectionBatcherInterface[] */ private array $batchers = []; + private int $batchSize; + public function __construct( BatcherFactoryInterface $batcherFactory, QueryRebuilderInterface $queryRebuilder, EventDispatcherInterface $eventDispatcher, ManagerRegistry $managerRegistry, - string $class + string $class, + int $batchSize = 100 ) { $this->batcherFactory = $batcherFactory; $this->queryRebuilder = $queryRebuilder; $this->eventDispatcher = $eventDispatcher; $this->managerRegistry = $managerRegistry; $this->class = $class; + $this->batchSize = $batchSize; } public function getClass(): string @@ -59,12 +61,12 @@ public function getClass(): string */ public function getBatches(ChannelInterface $channel, LocaleInterface $locale): iterable { - yield from $this->getBatcher($channel, $locale)->getBatches(self::BATCH_SIZE); + yield from $this->getBatcher($channel, $locale)->getBatches($this->batchSize); } public function getBatchCount(ChannelInterface $channel, LocaleInterface $locale): int { - return $this->getBatcher($channel, $locale)->getBatchCount(self::BATCH_SIZE); + return $this->getBatcher($channel, $locale)->getBatchCount($this->batchSize); } /** @psalm-suppress MixedReturnTypeCoercion */