KeysetBatches
in package
Reads a large set in batches by key (`id > last id`, `ORDER BY id`, `LIMIT n`).
Sitemap and feed used to load the whole set with one findAll(). A keyset batch does not depend
on gaps in ids or on the number of empty ranges and keeps only one batch in memory; the caller
drops it after processing (an Api read also calls UnitOfWork::clear() at its start, so the
previous batch disappears from the UoW when the next one is loaded).
The end: an empty batch, an incomplete batch or an exhausted $totalLimit. A loader that does
not advance the cursor (returns an id <= the previous one) ends with an exception; otherwise the
loop would never finish.
Table of Contents
Methods
- iterate() : Generator<int, array<int, T>>
Methods
iterate()
public
static iterate(callable(int $afterId, int $limit): array<int, T> $loader, int $batchSize, callable(T): int $idOf[, int|null $totalLimit = null ][, int $afterId = 0 ]) : Generator<int, array<int, T>>
Parameters
- $loader : callable(int $afterId, int $limit): array<int, T>
-
returns rows with id >
$afterIdordered ascending by id - $batchSize : int
- $idOf : callable(T): int
- $totalLimit : int|null = null
-
cap on the total number of loaded rows (
null= no cap); rows from the loader are counted - $afterId : int = 0
-
initial cursor, to continue from a saved progress (partial reindex)