Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cache \yii\data\ActiveDataProvider::prepareTotalCount() #20206

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions framework/data/ActiveDataProvider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check failure on line 1 in framework/data/ActiveDataProvider.php

View workflow job for this annotation

GitHub Actions / PHP_CodeSniffer

Header blocks must be separated by a single blank line
/**
* @link https://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
Expand Down Expand Up @@ -151,8 +151,6 @@
return array_keys($models);
}

private $_totalCount = [];

/**
* {@inheritdoc}
*/
Expand All @@ -161,13 +159,8 @@
if (!$this->query instanceof QueryInterface) {
throw new InvalidConfigException('The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses.');
}
$query = (clone $this->query)->limit(-1)->offset(-1)->orderBy([]);
$key = md5((string)$query);

if (!array_key_exists($key, $this->_totalCount)) {
$this->_totalCount[$key] = (int)$query->count('*', $this->db);
}
return $this->_totalCount[$key];
$query = clone $this->query;
return (int) $query->limit(-1)->offset(-1)->orderBy([])->count('*', $this->db);
}

/**
Expand Down
Loading