Skip to content
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

Merged
merged 2 commits into from
May 3, 2017
Merged

Conversation

lcobucci
Copy link
Member

Simplifying test provided in #6390 and process the result set cache eviction when flag was passed.

@@ -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]
Copy link
Member

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.

Copy link
Member Author

@lcobucci lcobucci Apr 30, 2017

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 😱

@lcobucci lcobucci force-pushed the fix-expire-result-cache branch 2 times, most recently from 611816f to 4a6c0c6 Compare April 30, 2017 20:35
@@ -682,6 +689,11 @@ protected function _getEntityManager($config = null, $eventManager = null) {
self::$_queryCacheImpl = new ArrayCache();
}

if (is_null(self::$_resultCacheImpl)) {
Copy link
Member

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;
Copy link
Member

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?

Copy link
Member Author

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


$cacheDriver = $this->_queryCacheProfile->getResultCacheDriver();

foreach ((array) $executor->getSqlStatements() as $statement) {
Copy link
Member

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 :|

Copy link
Member Author

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)

Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure 😉

$cacheDriver = $this->_queryCacheProfile->getResultCacheDriver();

foreach ((array) $executor->getSqlStatements() as $statement) {
$cacheDriver->delete($this->_queryCacheProfile->generateCacheKeys($statement, $sqlParams, $types)[0]);
Copy link
Member

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

Copy link
Member Author

@lcobucci lcobucci May 2, 2017

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()?

Copy link
Member

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()
Copy link
Member

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)
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

except for : void 😭

Copy link
Member

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
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

@lcobucci lcobucci May 2, 2017

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 😉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding these :-)

/**
* @group 2947
*/
class GH2947Test extends OrmFunctionalTestCase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding these :-)

@Ocramius Ocramius merged commit 7bb02d0 into doctrine:master May 3, 2017
@Ocramius
Copy link
Member

Ocramius commented May 3, 2017

@lcobucci 🚢 \o/

@lcobucci lcobucci deleted the fix-expire-result-cache branch May 3, 2017 10:47
@lcobucci
Copy link
Member Author

lcobucci commented May 3, 2017

@Ocramius awesome thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants