-
Notifications
You must be signed in to change notification settings - Fork 30
2.8 _getCacheInternalId() is too generic #41
Comments
I can not reproduce this problem. I get always a correct / usable cache ID. Please test this short script: $select = new Zend\Db\Sql\Select('…'); // add a table name
$dbAdapter = new Zend\Db\Adapter\Adapter(
[
'driver' => '…', // add your database config
'database' => '…',
'username' => '…',
'password' => '…',
]
);
$adapter = new Zend\Paginator\Adapter\DbSelect($select, $dbAdapter);
$paginator = new Zend\Paginator\Paginator($adapter);
$cache = Zend\Cache\StorageFactory::adapterFactory(
Zend\Cache\Storage\Adapter\BlackHole::class
);
$paginator::setCache($cache);
var_dump($paginator->getItemsByPage(1)); Does this work for you? (Please recheck the internal cache ID.) |
There's another good reason for not using |
When I use the black hole adapter it appears to work fine. I am using the filesystem cache adapter and I am getting collisions:
|
same problem as reported by @richard-parnaby-king . |
I think I have found a solution, however I cannot run the unit tests - I am getting a fatal error:
I suspect the autoload generated by composer is incomplete, but I don't know how to fix it. Could someone: |
@richard-parnaby-king your solution would have the same problem of using I think the solution for Adapter\DbSelect would be using the SQL itself protected function _getCacheInternalId()
{
$adapter = $this->getAdapter();
if ($adapter instanceof \Zend\Paginator\Adapter\DbSelect) {
$reflection = new \ReflectionObject($adapter);
$property = $reflection->getProperty('select');
$property->setAccessible(true);
$select = $property->getValue($adapter);
return md5(
$reflection->getName()
. hash('sha512', $select->getSqlString())
. $this->getItemCountPerPage()
);
}
// @codingStandardsIgnoreEnd
return md5(
get_class($adapter)
. json_encode($adapter)
. $this->getItemCountPerPage()
);
} or make the changes in the Adapter\DbSelect to avoid the Reflection @Zend\Paginator\Paginator
protected function _getCacheInternalId()
{
$adapter = $this->getAdapter();
if ($adapter instanceof \Zend\Paginator\Adapter\DbSelect) {
return md5(
get_class($adapter)
. $adapter->getCacheId()
. $this->getItemCountPerPage()
}
// @codingStandardsIgnoreEnd
return md5(
get_class($adapter)
. json_encode($adapter)
. $this->getItemCountPerPage()
);
} @Zend\Paginator\Adapter\DbSelect
public function getCacheId()
{
return hash('sha512', $this->select->getSqlString())
} I could change the interface, but that probably would break someone @froschdesign what do you think? making a reflection is too ugly? |
@rcapile I've been deving on an mssql box so wasn't getting an uptime value. As such, I was getting the same value between requests. I agree with using the sql string as the source of the hash. |
@richard-parnaby-king I waiting for @froschdesign input to make a pull request. Although I think the right solution should be changing the we (we = @mariojrrc ) could make two pull request: one with the code above for the current version and another changing the interface for the next |
I see two problems here:
|
@froschdesign So the reflection is the best way? ou creating a public function |
I'm really sorry about the late response. Here is a simple idea: class DbSelect implements AdapterInterface, JsonSerializable
{
// ...
public function jsonSerialize()
{
return [
'select' => $this->sql->buildSqlString($this->select),
'count_select' => $this->sql->buildSqlString($this->getSelectCount()),
];
}
} (Edit: The select query for counting should also included. |
This repository has been closed and moved to laminas/laminas-paginator; a new issue has been opened at laminas/laminas-paginator#3. |
In
Zend\Paginator\Paginator::_getCacheInternalId()
(lines 863 - 871) the md5 hash of the adaptor being generated matches all adaptor instances. The issue is on line 868:This sucker is returning '{}' for all my table adaptors (adaptor being supplied is
Zend\Paginator\Adapter\DbSelect
).I don't understand the reason for replacing
spl_object_hash
, but I do ask how do I get my paginator instances working again?The text was updated successfully, but these errors were encountered: