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

Bring FilterCollection to a "clean" state after hash computation #9523

Merged
merged 4 commits into from
Feb 20, 2022

Conversation

mpdude
Copy link
Contributor

@mpdude mpdude commented Feb 17, 2022

Improvement

Q A
New Feature no
RFC no
BC Break no

Effectively, the FilterCollection was never brought back into a "clean" state after filters were enabled or filter parameters were set.

As far as I can tell, the clean/dirty distinction only refers to the computed FilterCollection hash reflecting all enabled filters and their parameters.

The only place I could find where the distinction matters is here:

// Return previous parser result if the query and the filter collection are both clean
if ($this->_state === self::STATE_CLEAN && $this->parsedTypes === $types && $this->_em->isFiltersStateClean()) {
return $this->parserResult;
}
$this->_state = self::STATE_CLEAN;
$this->parsedTypes = $types;
$queryCache = $this->queryCache ?? $this->_em->getConfiguration()->getQueryCache();
// Check query cache.
if (! ($this->useQueryCache && $queryCache)) {
$parser = new Parser($this);
$this->parserResult = $parser->parse();
return $this->parserResult;
}
$cacheItem = $queryCache->getItem($this->getQueryCacheId());

When the filter collection is dirty and the query cache is used, the call to getQueryCacheId() in the last line shown will reset the filter collection to a clean state.

When there is no query cache, however, getQueryCacheId() is not called and the FilterCollection will not revert to a clean state; this prevents re-using the query later on.

If desired, I could add a FilterCollection::setFiltersStateClean() method to improve this case as well.

Closes #9521

@derrabus derrabus added the Bug label Feb 17, 2022
@derrabus
Copy link
Member

Thank you. Can you please provide a test that reproduces the issue that your attempt to fix?

@mpdude
Copy link
Contributor Author

mpdude commented Feb 17, 2022

Can you please provide a test that reproduces the issue that your attempt to fix?

I don't know what I am trying to fix here 🐼 .

I came across this clean/dirty state distinction and figured it makes no sense the way it is implemented right now.

This PR is my guess what the original author might have intended and I'd be glad if this gets a bit more scrutiny.

derrabus
derrabus previously approved these changes Feb 20, 2022
@derrabus
Copy link
Member

I've added a test.

@derrabus derrabus enabled auto-merge (squash) February 20, 2022 13:02
@derrabus derrabus added this to the 2.11.2 milestone Feb 20, 2022
@derrabus derrabus merged commit 193c3ab into doctrine:2.11.x Feb 20, 2022
derrabus added a commit that referenced this pull request Feb 20, 2022
* 2.11.x:
  Bring `FilterCollection` to a "clean" state after hash computation (#9523)
@mpdude mpdude deleted the fix-filter-collection branch February 20, 2022 22:23
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.

2 participants