-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
2.8 _getCacheInternalId() is too generic #3
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.) Originally posted by @froschdesign at zendframework/zend-paginator#41 (comment) |
There's another good reason for not using Originally posted by @weierophinney at zendframework/zend-paginator#41 (comment) |
When I use the black hole adapter it appears to work fine. I am using the filesystem cache adapter and I am getting collisions:
Originally posted by @richard-parnaby-king at zendframework/zend-paginator#41 (comment) |
same problem as reported by @richard-parnaby-king . Originally posted by @mariojrrc at zendframework/zend-paginator#41 (comment) |
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: Originally posted by @richard-parnaby-king at zendframework/zend-paginator#41 (comment) |
@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? Originally posted by @rcapile at zendframework/zend-paginator#41 (comment) |
@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. Originally posted by @richard-parnaby-king at zendframework/zend-paginator#41 (comment) |
@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 Originally posted by @rcapile at zendframework/zend-paginator#41 (comment) |
I see two problems here:
Originally posted by @froschdesign at zendframework/zend-paginator#41 (comment) |
@froschdesign So the reflection is the best way? ou creating a public function Originally posted by @rcapile at zendframework/zend-paginator#41 (comment) |
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. Originally posted by @froschdesign at zendframework/zend-paginator#41 (comment) |
Signed-off-by: Frank Brückner <[email protected]>
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?Originally posted by @richard-parnaby-king at zendframework/zend-paginator#41
The text was updated successfully, but these errors were encountered: