Skip to content

Conversation

@k0ka
Copy link

@k0ka k0ka commented Jul 17, 2020

Q A
Type improvement
BC Break no
Fixed issues #4178

Summary

If the data is not found in the query cache, it will be queried again to append a new key to it. This PR removes the second fetching by passing the first result to ResultCacheStatement.

First cache fetch at Connection::executeCacheQuery():

$data = $resultCache->fetch($cacheKey);

Second cache fetch at ResultCacheStatement::saveToCache():
$data = $this->resultCache->fetch($this->cacheKey);

@greg0ire greg0ire added the Bug label Jul 22, 2020
Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

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

Please rebase, there is a conflict. Please also squash your commits.

* @param string $cacheKey
* @param string $realKey
* @param int $lifetime
* @param array<string,mixed>|null $fetchedData
Copy link
Member

Choose a reason for hiding this comment

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

Should this new argument become mandatory in 3.0.x?

Copy link
Author

Choose a reason for hiding this comment

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

I think, yes.
However, the class is renamed to CachingResult in 3.0

Copy link
Member

Choose a reason for hiding this comment

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

Why don't we implement a proper fix in 3.0.x first and then backport in a BC-way? Otherwise, it's not clear what the new intended logic is.

Copy link
Author

Choose a reason for hiding this comment

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

I don't know how you releasing process is working. I consider this bug as a minor so it doesn't make sense to break backward compatibility.

Copy link
Member

Choose a reason for hiding this comment

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

Let's at least make it clear in the parameter description that this parameter will be mandatory in 3.0. Otherwise, it's not clear why fetching the data has to be implemented twice.

Copy link
Author

Choose a reason for hiding this comment

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

I feel confused about how to do it all in 2.11.

I have opened the new #4189 for 3.0.x version with BC Break and mandatory $fetchedData field.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not that well familiar with the design of the caching layer and I still don't get the design: instead of fetching the data from the result, why does the result now use the fetched data and still can fetch from the result via fetch*() methods? Is this still necessary?

Copy link
Author

@k0ka k0ka Jul 24, 2020

Choose a reason for hiding this comment

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

The result cache is fetched in ResultCacheStatement only if no fetchedData is provided to the constructor. It is done for backward compatibility - someone could use ResultCacheStatement before and it should continue working without the last parameter.

DBAL uses this class only in one place and it always sends fetchedData. So, result cache won't be fetched 2 times if DBAL is used ordinarily.

Copy link
Member

Choose a reason for hiding this comment

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

The result cache is fetched in ResultCacheStatement only if no fetchedData is provided to the constructor.

Let's then continue the discussion in #4189 where BC is of no concern. The new class still depends on the Result.

@k0ka k0ka force-pushed the 2.11-double-cache-fetch branch from 3f847c0 to c61ef4a Compare July 22, 2020 19:55
@k0ka k0ka force-pushed the 2.11-double-cache-fetch branch from 9e290c8 to c3704d7 Compare July 22, 2020 20:18
@greg0ire greg0ire requested a review from morozov July 22, 2020 20:25
Copy link
Member

@morozov morozov left a comment

Choose a reason for hiding this comment

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

There are three new code execution branches and not a single test. There must be a unit test that covers the logic of interaction with the external cache.

$this->fetchedData = $this->resultCache->fetch($this->cacheKey);
}

if (! $this->fetchedData) {
Copy link
Member

Choose a reason for hiding this comment

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

Please avoid implicit conversion to boolean. It's not allowed in newer branches.

Copy link
Author

@k0ka k0ka Jul 23, 2020

Choose a reason for hiding this comment

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

Ok. This line was written before me - I've just change the variable name.

$stmt = new ArrayStatement([]);
}
} else {
$data = [];
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Author

@k0ka k0ka Jul 23, 2020

Choose a reason for hiding this comment

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

It is needed to distinguish "data from query cache is not loaded" and "data from query cache is loaded and empty".
This data was be set to empty array in ResultCacheStatement before -

@morozov morozov changed the base branch from 2.11.x to 2.12.x November 29, 2020 21:38
@morozov morozov closed this Apr 21, 2021
@morozov morozov deleted the branch doctrine:2.12.x April 21, 2021 16:26
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DDC-2043: Extra cache operation in DBAL\Cache\ResultCacheStatement.php

3 participants