Created
June 28, 2010 12:20
-
-
Save co3k/455772 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: lib/util/opDoctrineQuery.class.php | |
=================================================================== | |
--- lib/util/opDoctrineQuery.class.php | |
+++ lib/util/opDoctrineQuery.class.php | |
@@ -18,13 +18,15 @@ | |
class opDoctrineQuery extends Doctrine_Query | |
{ | |
protected static | |
- $detectedSlave = null; | |
+ $detectedSlave = null, | |
+ $findQueryCacheKeys = array(); | |
protected | |
$shouldGoToMaster = false, | |
$isFoundRows = false, | |
$specifiedConnection = null, | |
- $whereInCount = ''; | |
+ $whereInCount = '', | |
+ $cachedQueryCacheHash = ''; | |
public function connectToMaster($isMaster = false) | |
{ | |
@@ -198,7 +200,39 @@ | |
public function calculateQueryCacheHash() | |
{ | |
- $result = parent::calculateQueryCacheHash(); | |
+ if ($this->cachedQueryCacheHash) | |
+ { | |
+ $result = $this->cachedQueryCacheHash; | |
+ | |
+ $this->cachedQueryCacheHash = ''; | |
+ | |
+ return $result; | |
+ } | |
+ | |
+ $result = ''; | |
+ $findQueryCacheKey = ''; | |
+ | |
+ if (isset($this->_dqlParts['from'][0])) | |
+ { | |
+ if (strpos($this->_dqlParts['from'][0], 'dctrn_find')) | |
+ { | |
+ $findQueryCacheKey = md5($this->_dqlParts['from'][0].count($this->getFlattenedParams())); | |
+ } | |
+ | |
+ if (isset(self::$findQueryCacheKeys[$findQueryCacheKey])) | |
+ { | |
+ $result = self::$findQueryCacheKeys[$findQueryCacheKey]; | |
+ } | |
+ } | |
+ | |
+ if (!$result) | |
+ { | |
+ $result = parent::calculateQueryCacheHash(); | |
+ if ($findQueryCacheKey) | |
+ { | |
+ self::$findQueryCacheKeys[$findQueryCacheKey] = $result; | |
+ } | |
+ } | |
if ($this->isFoundRows) | |
{ | |
@@ -213,6 +247,11 @@ | |
return $result; | |
} | |
+ public function setCachedQueryCacheHash($hash) | |
+ { | |
+ $this->cachedQueryCacheHash = $hash; | |
+ } | |
+ | |
protected function _buildSqlQueryBase() | |
{ | |
switch ($this->_type) | |
@@ -232,4 +271,9 @@ | |
return $q; | |
} | |
+ | |
+ public function getFrom() | |
+ { | |
+ return $this->_dqlParts['from']; | |
+ } | |
} | |
Index: lib/util/opDoctrineConnectionMysql.class.php | |
=================================================================== | |
--- lib/util/opDoctrineConnectionMysql.class.php | |
+++ lib/util/opDoctrineConnectionMysql.class.php | |
@@ -17,6 +17,8 @@ | |
*/ | |
class opDoctrineConnectionMysql extends Doctrine_Connection_Mysql | |
{ | |
+ protected $hashByQuery = array(); | |
+ | |
public function quoteIdentifier($str, $checkOption = true) | |
{ | |
// non-identifiers | |
@@ -39,4 +41,27 @@ | |
return parent::quoteIdentifier($str, $checkOption); | |
} | |
+ | |
+ public function query($query, array $params = array(), $hydrationMode = null) | |
+ { | |
+ $parser = Doctrine_Query::create(); | |
+ | |
+ $key = md5($query); | |
+ if (isset($this->hashByQuery[$key])) | |
+ { | |
+ $parser->setCachedQueryCacheHash($this->hashByQuery[$key][0]); | |
+ $parser->from(implode(',', $this->hashByQuery[$key][1])); | |
+ | |
+ $res = $parser->execute($params, $hydrationMode); | |
+ } | |
+ else | |
+ { | |
+ $res = $parser->query($query, $params, $hydrationMode); | |
+ $this->hashByQuery[$key] = array($parser->calculateQueryCacheHash(), $parser->getFrom()); | |
+ } | |
+ | |
+ $parser->free(); | |
+ | |
+ return $res; | |
+ } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment