This commit is contained in:
parent
0b819a2919
commit
2973b274e4
@ -125,6 +125,8 @@ class Doctrine_Hydrate implements Serializable
|
|||||||
* @see Doctrine_Query::* constants
|
* @see Doctrine_Query::* constants
|
||||||
*/
|
*/
|
||||||
protected $type = self::SELECT;
|
protected $type = self::SELECT;
|
||||||
|
|
||||||
|
protected $_cache;
|
||||||
|
|
||||||
protected $_tableAliases = array();
|
protected $_tableAliases = array();
|
||||||
/**
|
/**
|
||||||
@ -150,6 +152,14 @@ class Doctrine_Hydrate implements Serializable
|
|||||||
{
|
{
|
||||||
return $this->getQuery();
|
return $this->getQuery();
|
||||||
}
|
}
|
||||||
|
public function setCache(Doctrine_Cache_Interface $cache)
|
||||||
|
{
|
||||||
|
$this->_cache = $cache;
|
||||||
|
}
|
||||||
|
public function getCache()
|
||||||
|
{
|
||||||
|
return $this->_cache;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* serialize
|
* serialize
|
||||||
* this method is automatically called when this Doctrine_Hydrate is serialized
|
* this method is automatically called when this Doctrine_Hydrate is serialized
|
||||||
@ -627,12 +637,12 @@ class Doctrine_Hydrate implements Serializable
|
|||||||
*/
|
*/
|
||||||
public function execute($params = array(), $return = Doctrine::FETCH_RECORD)
|
public function execute($params = array(), $return = Doctrine::FETCH_RECORD)
|
||||||
{
|
{
|
||||||
if ($this->_options['resultSetCache']) {
|
if ($this->_cache) {
|
||||||
$dql = $this->getDql();
|
$dql = $this->getDql();
|
||||||
// calculate hash for dql query
|
// calculate hash for dql query
|
||||||
$hash = strlen($dql) . md5($dql);
|
$hash = strlen($dql) . md5($dql);
|
||||||
|
|
||||||
$cached = $this->_options['resultSetCache']->fetch($hash);
|
$cached = $this->_cache->fetch($hash);
|
||||||
|
|
||||||
if ($cached === null) {
|
if ($cached === null) {
|
||||||
// cache miss
|
// cache miss
|
||||||
@ -640,7 +650,7 @@ class Doctrine_Hydrate implements Serializable
|
|||||||
|
|
||||||
$cached = $this->getCachedForm($array);
|
$cached = $this->getCachedForm($array);
|
||||||
|
|
||||||
$this->_options['resultSetCache']->save($hash, $cached);
|
$this->_cache->save($hash, $cached);
|
||||||
} else {
|
} else {
|
||||||
$cached = unserialize($cached);
|
$cached = unserialize($cached);
|
||||||
$this->_tableAliases = $cached[2];
|
$this->_tableAliases = $cached[2];
|
||||||
|
@ -247,7 +247,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check for cache
|
// check for cache
|
||||||
if ( ! $this->_options['resultSetCache'] && ! $this->_options['parserCache']) {
|
if ( ! $this->_options['resultSetCache']) {
|
||||||
$parser = $this->getParser($queryPartName);
|
$parser = $this->getParser($queryPartName);
|
||||||
|
|
||||||
$sql = $parser->parse($queryPart);
|
$sql = $parser->parse($queryPart);
|
||||||
@ -619,21 +619,10 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
|||||||
public function getQuery($params = array())
|
public function getQuery($params = array())
|
||||||
{
|
{
|
||||||
// check if parser cache is on
|
// check if parser cache is on
|
||||||
if ($this->_options['resultSetCache'] !== false) {
|
if ($this->_cache) {
|
||||||
/**
|
|
||||||
$dql = $this->getDql();
|
|
||||||
// calculate hash for dql query
|
|
||||||
$hash = strlen($dql) . md5($dql);
|
|
||||||
|
|
||||||
// check if cache has sql equivalent for given hash
|
|
||||||
$sql = $this->_options['parserCache']->fetch($hash, true);
|
|
||||||
if ($sql !== null) {
|
|
||||||
return $sql;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
// cache miss, build sql query from dql parts
|
|
||||||
foreach ($this->_dqlParts as $queryPartName => $queryParts) {
|
foreach ($this->_dqlParts as $queryPartName => $queryParts) {
|
||||||
if (is_array($queryParts) && ! empty($queryParts)) {
|
if (is_array($queryParts) && ! empty($queryParts)) {
|
||||||
|
|
||||||
foreach ($queryParts as $queryPart) {
|
foreach ($queryParts as $queryPart) {
|
||||||
$this->getParser($queryPartName)->parse($queryPart);
|
$this->getParser($queryPartName)->parse($queryPart);
|
||||||
}
|
}
|
||||||
@ -721,10 +710,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
|||||||
array_shift($this->parts['where']);
|
array_shift($this->parts['where']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// append sql query into cache
|
|
||||||
if ($this->_options['parserCache'] !== false) {
|
|
||||||
$this->_options['parserCache']->save($hash, $q);
|
|
||||||
}
|
|
||||||
return $q;
|
return $q;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user