Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Critical
-
Resolution: Fixed
-
Affects Version/s: 1.6.0
-
Fix Version/s: 1.10.5
-
Component/s: Zend_Paginator
-
Labels:None
Description
Hello,
I found a bug in Zend_Paginator. If we enable caching of queries to the database through Zend_Paginator:
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
Zend_Paginator::setCache($cache);
....and then run the page with the following code:
$news = new Default_Model_DbTable_News(); $select = $news->select(); $paginator = Zend_Paginator::factory($select); $page = (int)$this->_getParam('page', 1); $paginator->setItemCountPerPage(1); $paginator->setCurrentPageNumber($page); $this->view->result = $paginator;
...it will execute 4 queries:
0.00359 connect NULL
0.00019 SELECT COUNT(1) AS `zend_paginator_row_count` FROM `news` NULL
0.00067 connect NULL
0.0003 SELECT `news`.* FROM `news` LIMIT 1 NULL
Also, it always creates a new cache with different name even though it performed the same query. I found function in code, which is responsible for generating name of cache
return md5(serialize($this->getAdapter()) . $this->getItemCountPerPage());
The problem is that the serialized object (Zend_Paginator_Adapter_DbSelect) when Zend_Db_Profiler is enable, has also included a unique time measurement queries. So we can be 100% sure that the result of function md5() will be different every time. Also, when we execute the function serialize() of adapter, Zend_Db disconnect from the database.
I prepared an initial fix, which solves the problem with the cache and re-connecting to the database. Zend_Paginator_Adapter_DbSelect class should implement Serializable interface (although I think it should all implement adapters, not only DbSelect):
class Zend_Paginator_Adapter_DbSelect implements Zend_Paginator_Adapter_Interface, Serializable { ... public function serialize() { return serialize($this->_select->__toString()); } public function unserialize($data) {} ... }
I hope that this bug will be fixed soon.
Regards
deallas
Issue Links
| This issue duplicates: | ||||
| ZF-6989 | Zend_Paginator DbSelect should not use Select object in serialization |
|
|
|
Added formatting