MediaWiki master
|
Allows iterating a large number of rows in batches transparently. More...
Inherits RecursiveIterator.
Public Member Functions | |
__construct (IReadableDatabase $db, $sqb, $primaryKey, $batchSize) | |
addConditions (array $conditions) | |
addJoinConditions (array $conditions) | |
addOptions (array $options) | |
current () | |
extractPrimaryKeys ( $row) | |
Extracts the primary key(s) from a database row. | |
getChildren () | |
hasChildren () | |
key () | |
next () | |
Fetch the next set of rows from the database. | |
rewind () | |
Reset the iterator to the beginning of the table. | |
setCaller ( $caller) | |
Use ->setCaller( METHOD ) to indicate which code is using this class. | |
setFetchColumns (array $columns) | |
valid () | |
Public Attributes | |
SelectQueryBuilder | $sqb |
Underlying database query builder, may be mutated before iteration begins. | |
Protected Member Functions | |
buildConditions () | |
Uses the primary key list and the maximal result row from the previous iteration to build an SQL condition sufficient for selecting the next page of results. | |
Protected Attributes | |
int | $batchSize |
The number of rows to fetch per iteration. | |
IReadableDatabase | $db |
array | $primaryKey |
The name of the primary key(s) | |
Allows iterating a large number of rows in batches transparently.
By default when iterated over returns the full query result as an array of rows. Can be wrapped in RecursiveIteratorIterator to collapse those arrays into a single stream of rows queried in batches.
Definition at line 34 of file BatchRowIterator.php.
BatchRowIterator::__construct | ( | IReadableDatabase | $db, |
$sqb, | |||
$primaryKey, | |||
$batchSize ) |
IReadableDatabase | $db | |
SelectQueryBuilder | string | array | $sqb | The query to split into batches (or table name/names) |
string | array | $primaryKey | The name or names of the primary key columns |
int | $batchSize | The number of rows to fetch per iteration |
Definition at line 71 of file BatchRowIterator.php.
References $batchSize, $db, $primaryKey, $sqb, and Wikimedia\Rdbms\IReadableDatabase\newSelectQueryBuilder().
BatchRowIterator::addConditions | ( | array | $conditions | ) |
array | $conditions | Query conditions suitable for use with IDatabase::select |
Definition at line 94 of file BatchRowIterator.php.
BatchRowIterator::addJoinConditions | ( | array | $conditions | ) |
array | $conditions | Query join conditions suitable for use with IDatabase::select |
Definition at line 112 of file BatchRowIterator.php.
BatchRowIterator::addOptions | ( | array | $options | ) |
array | $options | Query options suitable for use with IDatabase::select |
Definition at line 103 of file BatchRowIterator.php.
|
protected |
Uses the primary key list and the maximal result row from the previous iteration to build an SQL condition sufficient for selecting the next page of results.
Definition at line 230 of file BatchRowIterator.php.
BatchRowIterator::current | ( | ) |
Definition at line 167 of file BatchRowIterator.php.
BatchRowIterator::extractPrimaryKeys | ( | $row | ) |
Extracts the primary key(s) from a database row.
stdClass | $row | An individual database row from this iterator |
Definition at line 155 of file BatchRowIterator.php.
BatchRowIterator::getChildren | ( | ) |
Definition at line 201 of file BatchRowIterator.php.
BatchRowIterator::hasChildren | ( | ) |
Definition at line 197 of file BatchRowIterator.php.
BatchRowIterator::key | ( | ) |
Definition at line 174 of file BatchRowIterator.php.
BatchRowIterator::next | ( | ) |
Fetch the next set of rows from the database.
Definition at line 208 of file BatchRowIterator.php.
BatchRowIterator::rewind | ( | ) |
Reset the iterator to the beginning of the table.
Definition at line 181 of file BatchRowIterator.php.
BatchRowIterator::setCaller | ( | $caller | ) |
Use ->setCaller( METHOD ) to indicate which code is using this class.
Only used in debugging output.
string | $caller |
Definition at line 143 of file BatchRowIterator.php.
BatchRowIterator::setFetchColumns | ( | array | $columns | ) |
array | $columns | List of column names to select from the table suitable for use with IDatabase::select() |
Definition at line 121 of file BatchRowIterator.php.
BatchRowIterator::valid | ( | ) |
Definition at line 190 of file BatchRowIterator.php.
|
protected |
The number of rows to fetch per iteration.
Definition at line 46 of file BatchRowIterator.php.
Referenced by __construct().
|
protected |
Definition at line 36 of file BatchRowIterator.php.
Referenced by __construct().
|
protected |
The name of the primary key(s)
Definition at line 41 of file BatchRowIterator.php.
Referenced by __construct().
SelectQueryBuilder BatchRowIterator::$sqb |
Underlying database query builder, may be mutated before iteration begins.
Definition at line 61 of file BatchRowIterator.php.
Referenced by __construct().