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(serializer): empty object as array with supports cache #5100

Merged
merged 4 commits into from
Nov 12, 2022

Conversation

soyuka
Copy link
Member

@soyuka soyuka commented Oct 27, 2022

reverts #4999 and re-implement it

if ('' === $operationName && \in_array($operation->getMethod() ?? HttpOperation::METHOD_GET, [HttpOperation::METHOD_GET, HttpOperation::METHOD_OPTIONS, HttpOperation::METHOD_HEAD], true) && ($forceCollection ? $isCollection : !$isCollection)) {
$method = $operation->getMethod() ?? HttpOperation::METHOD_GET;
$isGetOperation = HttpOperation::METHOD_GET === $method || HttpOperation::METHOD_OPTIONS === $method || HttpOperation::METHOD_HEAD === $method;
if ('' === $operationName && $isGetOperation && ($forceCollection ? $isCollection : !$isCollection)) {
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 taking this PR as an opportunity for a long time question I have: is adding an empty string as key in the operationCache a good idea?

Copy link
Member Author

Choose a reason for hiding this comment

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

I need to prefix these, but yeah the representation of null as string would be an empty string ?

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 sure to follow: if we ask a null $operationName to this getOperation method, it means we don't know the operation name. It it is cached, the same operation is always returned, even if the other conditions have changed ($isGetOperation, $forceCollection...). It seems dangerous to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's fix this in another patch then.

src/Metadata/Resource/ResourceMetadataCollection.php Outdated Show resolved Hide resolved
src/Serializer/AbstractCollectionNormalizer.php Outdated Show resolved Hide resolved
src/Serializer/AbstractItemNormalizer.php Outdated Show resolved Hide resolved
@soyuka soyuka deleted the branch api-platform:3.0 November 4, 2022 19:11
@soyuka soyuka closed this Nov 4, 2022
@soyuka soyuka reopened this Nov 6, 2022
@soyuka soyuka force-pushed the fix/performance-issue branch from 300174b to c0f7114 Compare November 9, 2022 08:08
@soyuka soyuka merged commit 6e2f920 into api-platform:3.0 Nov 12, 2022
@soyuka soyuka deleted the fix/performance-issue branch November 12, 2022 08:53
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.

3 participants