Skip to content

Commit 57abc39

Browse files
committed
ACPT-677: Catalog product grid improvement
- Add limit to display total number of records;
1 parent 4c6c053 commit 57abc39

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

app/code/Magento/Catalog/Ui/DataProvider/Product/ProductCollection.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
*/
1515
class ProductCollection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
1616
{
17+
/**
18+
* Limit to display/hide total number of products in grid
19+
*/
20+
private const RECORDS_LIMIT = 20000;
21+
1722
/**
1823
* Disables using of price index for grid rendering
1924
*
@@ -35,7 +40,26 @@ public function getSize()
3540
{
3641
if ($this->_scopeConfig->getValue('admin/grid/show_approximate_total_number_of_products')) {
3742
$sql = $this->getSelectCountSql();
38-
return $this->analyzeCount($sql);
43+
$estimatedCount = $this->analyzeCount($sql);
44+
45+
if ($estimatedCount < self::RECORDS_LIMIT) {
46+
$columns = $sql->getPart(Select::COLUMNS);
47+
$sql->reset(Select::COLUMNS);
48+
49+
foreach ($columns as &$column) {
50+
if ($column[1] instanceof \Zend_Db_Expr && $column[1] == "COUNT(DISTINCT e.entity_id)") {
51+
$column[1] = new \Zend_Db_Expr('DISTINCT e.entity_id');
52+
}
53+
}
54+
$sql->setPart(Select::COLUMNS, $columns);
55+
$sql->limit(self::RECORDS_LIMIT);
56+
57+
$query = new \Zend_Db_Expr('SELECT COUNT(*) FROM (' . $sql->assemble() . ') AS c');
58+
59+
return $this->getConnection()->query($query)->fetchColumn();
60+
} else {
61+
return self::RECORDS_LIMIT;
62+
}
3963
}
4064

4165
return parent::getSize();

0 commit comments

Comments
 (0)