1
0
mirror of synced 2025-01-29 19:41:45 +03:00

[DDC-551] Added filters to query hash + tests for hash

This commit is contained in:
Alexander 2011-07-22 17:01:18 +02:00
parent 6163d9d932
commit e3dcfa8702
2 changed files with 43 additions and 1 deletions

View File

@ -556,14 +556,32 @@ final class Query extends AbstractQuery
{ {
ksort($this->_hints); ksort($this->_hints);
return md5( return md5(
$this->getDql() . var_export($this->_hints, true) . $this->getDql() . var_export($this->_hints, true) .
var_export($this->_em->getEnabledFilters(), true) . $this->getFilterHash() .
'&firstResult=' . $this->_firstResult . '&maxResult=' . $this->_maxResults . '&firstResult=' . $this->_firstResult . '&maxResult=' . $this->_maxResults .
'&hydrationMode='.$this->_hydrationMode.'DOCTRINE_QUERY_CACHE_SALT' '&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. * Cleanup Query resource when clone is called.
* *

View File

@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Functional;
use Doctrine\ORM\Query\Filter\SQLFilter; use Doctrine\ORM\Query\Filter\SQLFilter;
use Doctrine\ORM\Mapping\ClassMetaData; use Doctrine\ORM\Mapping\ClassMetaData;
use Doctrine\Common\Cache\ArrayCache;
require_once __DIR__ . '/../../TestInit.php'; require_once __DIR__ . '/../../TestInit.php';
@ -16,6 +17,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase
{ {
public function setUp() public function setUp()
{ {
$this->useModelSet('cms');
parent::setUp(); parent::setUp();
} }
@ -191,6 +193,28 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals(serialize($parameters), ''.$filter); $this->assertEquals(serialize($parameters), ''.$filter);
$this->assertEquals(''.$filter, ''.$filter2); $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 class MySoftDeleteFilter extends SQLFilter