Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SourceRowSizeEstimator.php
Go to the documentation of this file.
1 <?php
8 
14 
25 {
29  private $storeManagement;
30 
34  private $indexerResource;
35 
39  private $metadataPool;
40 
46  public function __construct(
47  StoreManagementInterface $storeManagement,
48  Source $indexerResource,
49  MetadataPool $metadataPool
50  ) {
51  $this->storeManagement = $storeManagement;
52  $this->indexerResource = $indexerResource;
53  $this->metadataPool = $metadataPool;
54  }
55 
59  public function estimateRowSize()
60  {
61  $connection = $this->indexerResource->getConnection();
62  $entityIdField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
63 
64  $maxRowsPerStore = max(
65  $this->getMaxRowsPerStore(
67  $this->indexerResource->getTable('catalog_product_entity_int'),
68  $entityIdField
69  ),
70  $this->getMaxRowsPerStore(
72  $this->indexerResource->getTable('catalog_product_entity_varchar'),
73  $entityIdField
74  )
75  );
76 
77  return ceil($maxRowsPerStore * $this->storeManagement->getCount() * 500);
78  }
79 
88  private function getMaxRowsPerStore(
90  $valueTable,
91  $entityIdField
92  ) {
93  $valueSelect = $connection->select();
94  $valueSelect->from(
95  ['value_table' => $valueTable],
96  ['count' => new \Zend_Db_Expr('count(value_table.value_id)')]
97  );
98  $valueSelect->group([$entityIdField, 'store_id']);
99 
100  $maxSelect = $connection->select();
101  $maxSelect->from(
102  ['max_value' => $valueSelect],
103  ['count' => new \Zend_Db_Expr('MAX(count)')]
104  );
105  return $connection->fetchOne($maxSelect);
106  }
107 }
__construct(StoreManagementInterface $storeManagement, Source $indexerResource, MetadataPool $metadataPool)
$connection
Definition: bulk.php:13