8000 [Serializer] Do not cache attributes if `attributes` in context by sroze · Pull Request #25185 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Serializer] Do not cache attributes if attributes in context #25185

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

Merged

Conversation

sroze
Copy link
Contributor
@sroze sroze commented Nov 28, 2017
Q A
Branch? 3.3
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #25108
License MIT
Doc PR ø

Caching attributes based on the class works only when these attributes are not overwritten. This disables the cache when they are.

To me, this extractAttributes method should actually be a AttributeResolver dependency that can be decorated using different caching strategies I'd say but... that's a much bigger refactoring that needs more reflection with @dunglas.

@sroze sroze force-pushed the bugfix-25108-do-not-cache-attributes-if-in-context branch from 98561d4 to 303280d Compare November 28, 2017 09:26
@@ -126,7 +126,7 @@ protected function getAttributes($object, $format = null, array $context)
return $allowedAttributes;
}

if (isset($this->attributesCache[$class])) {
if (isset($this->attributesCache[$class]) && !isset($context['attributes'])) {
Copy link
Member
@lyrixx lyrixx Nov 28, 2017

Choose a reason for hiding this comment

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

If $context['attributes'] is defined, we will fill the $this->attributesCache[$class] array with useless values.

IMHO, the correct patch is:

if (!isset($context['attributes']}
     return $this->extractAttributes($object, $format, $context);
}

before the cache layer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, updated.

@nicolas-grekas nicolas-grekas added this to the 3.3 milestone Nov 28, 2017
@sroze sroze force-pushed the bugfix-25108-do-not-cache-attributes-if-in-context branch from 303280d to 6e87382 Compare November 28, 2017 12:04
@fabpot
Copy link
Member
fabpot commented Nov 29, 2017

Thank you @sroze.

@fabpot fabpot merged commit 6e87382 into symfony:3.3 Nov 29, 2017
fabpot added a commit that referenced this pull request Nov 29, 2017
…ntext (sroze)

This PR was merged into the 3.3 branch.

Discussion
----------

[Serializer] Do not cache attributes if `attributes` in context

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #25108
| License       | MIT
| Doc PR        | ø

Caching attributes based on the class works only when these attributes are not overwritten. This disables the cache when they are.

To me, this `extractAttributes` method should actually be a `AttributeResolver` dependency that can be decorated using different caching strategies I'd say but... that's a much bigger refactoring that needs more reflection with @dunglas.

Commits
-------

6e87382 Do not cache cache attributes if `attributes` is in the context
This was referenced Nov 30, 2017
@sroze sroze deleted the bugfix-25108-do-not-cache-attributes-if-in-context branch January 15, 2018 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0