Skip to content

fix(serializer): empty object as array with supports cache #5100

Merged
soyuka merged 4 commits into
api-platform:3.0from
soyuka:fix/performance-issue
Nov 12, 2022
Merged

fix(serializer): empty object as array with supports cache #5100
soyuka merged 4 commits into
api-platform:3.0from
soyuka:fix/performance-issue

Conversation

@soyuka

@soyuka soyuka commented Oct 27, 2022

Copy link
Copy Markdown
Member

reverts #4999 and re-implement it

Comment thread src/Hydra/Serializer/CollectionFiltersNormalizer.php Outdated
Comment thread src/Hydra/Serializer/CollectionNormalizer.php Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread src/Metadata/Resource/ResourceMetadataCollection.php Outdated
Comment thread src/Serializer/AbstractCollectionNormalizer.php Outdated
Comment thread src/Serializer/AbstractItemNormalizer.php Outdated
@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