Skip to content

Commit

Permalink
Merge pull request #249 from PatchRanger/master
Browse files Browse the repository at this point in the history
Fix findOne: it missed $record in case of no cache
  • Loading branch information
Sammaye committed Mar 24, 2015
2 parents b90b717 + dec9456 commit a2fb31d
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions EMongoDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -804,20 +804,18 @@ public function findOne($criteria = array(), $fields = array())
'Executing findOne: '.'{$query:' . json_encode($query) . ',$project:' . json_encode($project) . '}',
'extensions.MongoYii.EMongoDocument'
);

if(
$this->getDbConnection()->queryCachingCount > 0
$this->getDbConnection()->queryCachingCount > 0
&& $this->getDbConnection()->queryCachingDuration > 0
&& $this->getDbConnection()->queryCacheID !== false
&& ($cache = Yii::app()->getComponent($this->getDbConnection()->queryCacheID)) !== null
&& ($cache = Yii::app()->getComponent($this->getDbConnection()->queryCacheID))
&& ($cacheKey = 'yii:dbquery'.$this->getDbConnection()->server.':'.$this->getDbConnection()->db .':'.$this->getDbConnection()->getSerialisedQuery($query, $project).':'.$this->getCollection())
&& ($result = $cache->get($cacheKey)) !== false
){
$this->getDbConnection()->queryCachingCount--;
$cacheKey = 'yii:dbquery' . $this->getDbConnection()->server . ':' . $this->getDbConnection()->db;
$cacheKey .= ':' . $this->getDbConnection()->getSerialisedQuery($query, $project) . ':' . $this->getCollection();
if(($result = $cache->get($cacheKey)) !== false){
Yii::trace('Query result found in cache', 'extensions.MongoYii.EMongoDocument');
$record = $result[0];
}
Yii::trace('Query result found in cache', 'extensions.MongoYii.EMongoDocument');
$record = $result[0];
}else{
if($this->getDbConnection()->enableProfiling){
Yii::beginProfile(
Expand Down Expand Up @@ -1458,4 +1456,4 @@ public function trace($func)
{
Yii::trace(get_class($this) . '.' . $func . '()', 'extensions.MongoYii.EMongoDocument');
}
}
}

0 comments on commit a2fb31d

Please sign in to comment.