Skip to content

Commit

Permalink
Add batch size as a constructor argument
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Sep 13, 2023
1 parent 68f93e1 commit 4f7e406
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/DataProvider/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

class DataProvider implements DataProviderInterface
{
private const BATCH_SIZE = 100;

private BatcherFactoryInterface $batcherFactory;

private QueryRebuilderInterface $queryRebuilder;
Expand All @@ -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
Expand All @@ -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 */
Expand Down

0 comments on commit 4f7e406

Please sign in to comment.