BatchProviderInterface.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Indexer;
  7. use Magento\Framework\DB\Adapter\AdapterInterface;
  8. use Magento\Framework\DB\Select;
  9. /**
  10. * Generator of consecutive entity ID ranges that must be handled as a batch.
  11. *
  12. * Can be used during indexation process to split large amount of data into batches
  13. * and process them one by one in order to reduce memory consumption and improve overall performance.
  14. *
  15. * @api retrieve Batches when implementing custom Indexer\Action
  16. * @since 101.0.0
  17. */
  18. interface BatchProviderInterface
  19. {
  20. /**
  21. * Retrieve batches (entity ID ranges) from the given table.
  22. *
  23. * @param AdapterInterface $adapter database adapter.
  24. * @param string $tableName target table name.
  25. * @param string $linkField field that is used as a record identifier.
  26. * @param int $batchSize size of the single range.
  27. * @return \Generator generator that produces entity ID ranges in the format of ['from' => ..., 'to' => ...]
  28. * @since 101.0.0
  29. */
  30. public function getBatches(AdapterInterface $adapter, $tableName, $linkField, $batchSize);
  31. /**
  32. * Get list of entity ids based on batch
  33. *
  34. * @param AdapterInterface $connection
  35. * @param Select $select
  36. * @param array $batch
  37. * @return array
  38. * @since 101.0.0
  39. */
  40. public function getBatchIds(AdapterInterface $connection, Select $select, array $batch);
  41. }