Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RowSizeEstimator.php
Go to the documentation of this file.
1 <?php
8 
10 
17 {
21  const ROW_MEMORY_SIZE = 100;
22 
26  private $resourceConnection;
27 
31  public function __construct(
32  \Magento\Framework\App\ResourceConnection $resourceConnection
33  ) {
34  $this->resourceConnection = $resourceConnection;
35  }
36 
47  public function estimateRowSize()
48  {
49  $connection = $this->resourceConnection->getConnection();
50 
51  // get store groups count except the default
52  $storeGroupSelect = $connection->select()
53  ->from(
54  $this->resourceConnection->getTableName('store_group'),
55  ['count' => new \Zend_Db_Expr('count(*)')]
56  )->where('group_id > 0');
57  $storeGroupCount = $connection->fetchOne($storeGroupSelect);
58 
59  // get max possible categories per product
60  // subselect with categories count per product
61  $categoryCounterSubSelect = $connection->select()
62  ->from(
63  $this->resourceConnection->getTableName('catalog_category_product'),
64  ['counter' => new \Zend_Db_Expr('count(category_id)')]
65  )->group('product_id');
66 
67  // select maximum value from subselect
68  $productCountSelect = $connection->select()
69  ->from(
70  ['counters' => $categoryCounterSubSelect],
71  [new \Zend_Db_Expr('max(counter)')]
72  );
73  $maxProducts = $connection->fetchOne($productCountSelect);
74 
75  return ceil($storeGroupCount * $maxProducts * self::ROW_MEMORY_SIZE);
76  }
77 }
__construct(\Magento\Framework\App\ResourceConnection $resourceConnection)
$connection
Definition: bulk.php:13