Fix #20175: Fix bad result for pagination when used with GridView

This commit is contained in:
Alex
2024-06-08 10:29:40 +03:00
committed by GitHub
parent f1ac78f578
commit 3fa2d61e54
19 changed files with 64 additions and 47 deletions

View File

@ -110,7 +110,6 @@ class ActiveDataProvider extends BaseDataProvider
if (($sort = $this->getSort()) !== false) {
$query->addOrderBy($sort->getOrders());
}
return $query->all($this->db);
}
@ -128,7 +127,6 @@ class ActiveDataProvider extends BaseDataProvider
$keys[] = call_user_func($this->key, $model);
}
}
return $keys;
} elseif ($this->query instanceof ActiveQueryInterface) {
/* @var $class \yii\db\ActiveRecordInterface */
@ -148,13 +146,13 @@ class ActiveDataProvider extends BaseDataProvider
$keys[] = $kk;
}
}
return $keys;
}
return array_keys($models);
}
private $_totalCount = [];
/**
* {@inheritdoc}
*/
@ -163,8 +161,13 @@ class ActiveDataProvider extends BaseDataProvider
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;
return (int) $query->limit(-1)->offset(-1)->orderBy([])->count('*', $this->db);
$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];
}
/**
@ -196,7 +199,6 @@ class ActiveDataProvider extends BaseDataProvider
if (is_object($this->query)) {
$this->query = clone $this->query;
}
parent::__clone();
}
}