Skip to content

Commit

Permalink
Added method to override the bulk request size in ProviderInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
pmishev committed Dec 17, 2020
1 parent bd50df6 commit 67adb26
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
12 changes: 11 additions & 1 deletion Document/Provider/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
abstract class AbstractProvider implements ProviderInterface
{

/**
* @var string The type the provider is for
*/
Expand Down Expand Up @@ -48,4 +47,15 @@ abstract public function getDocuments();
* @return DocumentInterface|array
*/
abstract public function getDocument($id);

/**
* Returns the number of Elasticsearch documents to persist in a single bulk request
* If null is returned, the 'bulk_batch_size' of the Connection will be used
*
* @return int|null
*/
public function getPersistRequestBatchSize() : ?int
{
return null;
}
}
8 changes: 8 additions & 0 deletions Document/Provider/ProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@ public function getDocuments();
* @return DocumentInterface|array
*/
public function getDocument($id);

/**
* Returns the number of Elasticsearch documents to persist in a single bulk request
* If null is returned, the 'bulk_batch_size' of the Connection will be used
*
* @return int|null
*/
public function getPersistRequestBatchSize() : ?int;
}
8 changes: 4 additions & 4 deletions Manager/IndexManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -687,15 +687,15 @@ protected function createNewIndexWithUniqueName()
*/
protected function copyDataToNewIndex(string $newIndex, string $oldIndex)
{
$batchSize = $this->connection->getConnectionSettings()['bulk_batch_size'];

// Make sure we don't autocommit on every item in the bulk request
$autocommit = $this->getConnection()->isAutocommit();
$this->getConnection()->setAutocommit(false);

$typeDataProvider = $this->getDataProvider();
$indexDataProvider = $this->getDataProvider();
$batchSize = $indexDataProvider->getPersistRequestBatchSize() ?? $this->connection->getConnectionSettings()['bulk_batch_size'];

$i = 1;
foreach ($typeDataProvider->getDocuments() as $document) {
foreach ($indexDataProvider->getDocuments() as $document) {
// Temporarily override the write alias with the new physical index name, so rebuilding only happens in the new index
$originalWriteAlias = $this->writeAlias;
$this->setWriteAlias($newIndex);
Expand Down

0 comments on commit 67adb26

Please sign in to comment.