File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed
app/code/Magento/Catalog/Ui/DataProvider/Product Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change 14
14
*/
15
15
class ProductCollection extends \Magento \Catalog \Model \ResourceModel \Product \Collection
16
16
{
17
+ /**
18
+ * Limit to display/hide total number of products in grid
19
+ */
20
+ private const RECORDS_LIMIT = 20000 ;
21
+
17
22
/**
18
23
* Disables using of price index for grid rendering
19
24
*
@@ -35,7 +40,26 @@ public function getSize()
35
40
{
36
41
if ($ this ->_scopeConfig ->getValue ('admin/grid/show_approximate_total_number_of_products ' )) {
37
42
$ 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
+ }
39
63
}
40
64
41
65
return parent ::getSize ();
You can’t perform that action at this time.
0 commit comments