-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix expire result cache #6417
Fix expire result cache #6417
Conversation
lib/Doctrine/ORM/Query.php
Outdated
@@ -322,6 +322,12 @@ protected function _doExecute() | |||
|
|||
list($sqlParams, $types) = $this->processParameterMappings($paramMappings); | |||
|
|||
if ($this->_queryCacheProfile && $this->getExpireResultCache()) { | |||
$this->_queryCacheProfile->getResultCacheDriver()->delete( | |||
$this->_queryCacheProfile->generateCacheKeys($executor->getSqlStatements(), $sqlParams, $types)[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is a list, iterate over it (even though now it only returns one item) and delete each record.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that but although the docblock says it returns an array
it can actually be string 😱
611816f
to
4a6c0c6
Compare
@@ -682,6 +689,11 @@ protected function _getEntityManager($config = null, $eventManager = null) { | |||
self::$_queryCacheImpl = new ArrayCache(); | |||
} | |||
|
|||
if (is_null(self::$_resultCacheImpl)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null ===
* | ||
* @var \Doctrine\Common\Cache\Cache|null | ||
*/ | ||
private static $_resultCacheImpl = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we introduce new properties, we shouldn't use the prefix... Also, the fact that this is a static smells a lot: what if it is accidentally not unset between test cycles? Is it supposed to always be set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True thing, I'll keep it non-static and leave the instantiation to the test that actually uses it. Thanks
lib/Doctrine/ORM/Query.php
Outdated
|
||
$cacheDriver = $this->_queryCacheProfile->getResultCacheDriver(); | ||
|
||
foreach ((array) $executor->getSqlStatements() as $statement) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the (array)
cast? Smelly :|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's indeed... cause: #6417 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lcobucci can you add that as a comment in the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure 😉
lib/Doctrine/ORM/Query.php
Outdated
$cacheDriver = $this->_queryCacheProfile->getResultCacheDriver(); | ||
|
||
foreach ((array) $executor->getSqlStatements() as $statement) { | ||
$cacheDriver->delete($this->_queryCacheProfile->generateCacheKeys($statement, $sqlParams, $types)[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That [0]
is also a bit smelly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you suggest? current()
? list()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reset()
or similar works fine
$this->brand = $brand; | ||
} | ||
|
||
public function __toString() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can start violently adding type hints everywhere
*/ | ||
public $brand; | ||
|
||
public function __construct($brand) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can start violently adding type hints everywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
except for : void
😭
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lcobucci bump it
/** | ||
* @group 2947 | ||
*/ | ||
class GH2947Test extends OrmFunctionalTestCase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a Query
-specific test that we can use here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As in a unit test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - are there no unit tests there? GH-XYZ tests are fine, but they make it hard to track supported features by looking at unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doctrine\Tests\ORM\Query\QueryTest#testResultCacheEviction()
not strictly a unit test though but should be enough 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding these :-)
4a6c0c6
to
e71272e
Compare
/** | ||
* @group 2947 | ||
*/ | ||
class GH2947Test extends OrmFunctionalTestCase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding these :-)
@lcobucci 🚢 \o/ |
@Ocramius awesome thanks! |
Simplifying test provided in #6390 and process the result set cache eviction when flag was passed.