Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SelectGenerator.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Framework\Db\Select;
11 
16 {
20  private $batchSize = 30000;
21 
25  private $baseBatchSize;
26 
30  private $resourceConnection;
31 
37  public function __construct(
38  ResourceConnection $resourceConnection,
39  $baseBatchSize = 30000
40  ) {
41  $this->baseBatchSize = $baseBatchSize;
42  $this->resourceConnection = $resourceConnection;
43  }
44 
54  public function generator(Select $select, $connectionName)
55  {
56  $page = 0;
57  $select->limit($this->batchSize, $page * $this->batchSize);
58  $adapter = $this->resourceConnection->getConnection($connectionName);
59  $data = $adapter->fetchAll($select);
60  yield $data;
61 
62  while (count($data)) {
63  ++$page;
64  $select->limit($this->batchSize, $page * $this->batchSize + 1);
65  $data = $adapter->fetchAll($select);
66  yield $data;
67  }
68  }
69 }
__construct(ResourceConnection $resourceConnection, $baseBatchSize=30000)
$adapter
Definition: webapi_user.php:16
$page
Definition: pages.php:8