[DDC-551] Added filters to query hash + tests for hash
This commit is contained in:
parent
6163d9d932
commit
e3dcfa8702
@ -556,14 +556,32 @@ final class Query extends AbstractQuery
|
||||
{
|
||||
ksort($this->_hints);
|
||||
|
||||
|
||||
return md5(
|
||||
$this->getDql() . var_export($this->_hints, true) .
|
||||
var_export($this->_em->getEnabledFilters(), true) .
|
||||
$this->getFilterHash() .
|
||||
'&firstResult=' . $this->_firstResult . '&maxResult=' . $this->_maxResults .
|
||||
'&hydrationMode='.$this->_hydrationMode.'DOCTRINE_QUERY_CACHE_SALT'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a string of currently enabled filters to use for the cache id.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getFilterHash()
|
||||
{
|
||||
$filterHash = '';
|
||||
|
||||
$filters = $this->_em->getEnabledFilters();
|
||||
foreach($filters as $name => $filter) {
|
||||
$filterHash .= $name . $filter;
|
||||
}
|
||||
|
||||
return $filterHash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup Query resource when clone is called.
|
||||
*
|
||||
|
@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Functional;
|
||||
|
||||
use Doctrine\ORM\Query\Filter\SQLFilter;
|
||||
use Doctrine\ORM\Mapping\ClassMetaData;
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
@ -16,6 +17,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->useModelSet('cms');
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
@ -191,6 +193,28 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertEquals(serialize($parameters), ''.$filter);
|
||||
$this->assertEquals(''.$filter, ''.$filter2);
|
||||
}
|
||||
|
||||
public function testQueryCache_DependsOnFilters()
|
||||
{
|
||||
$query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux');
|
||||
|
||||
$cache = new ArrayCache();
|
||||
$query->setQueryCacheDriver($cache);
|
||||
|
||||
$query->getResult();
|
||||
$this->assertEquals(1, count($cache->getIds()));
|
||||
|
||||
$conf = $this->_em->getConfiguration();
|
||||
$conf->addFilter("locale", "\Doctrine\Tests\ORM\Functional\MyLocaleFilter");
|
||||
$this->_em->enableFilter("locale");
|
||||
|
||||
$query->getResult();
|
||||
$this->assertEquals(2, count($cache->getIds()));
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class MySoftDeleteFilter extends SQLFilter
|
||||
|
Loading…
x
Reference in New Issue
Block a user