Skip to content

[HttpFoundation] Support root-level Generator in StreamedJsonResponse #51538

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
merged 1 commit into from
Oct 1, 2023

Conversation

Jeroeny
Copy link
Contributor

@Jeroeny Jeroeny commented Sep 2, 2023

Q A
Branch? 6.4
Bug fix? no
New feature? yes
Deprecations? no
License MIT

Currently the StreamedJsonResponse only supports streaming nested Generators within an array data structure.
However if a response is a list of items (for example database entities) on the root level, this isn't usable.
I think both usecases can be supported with the change in this PR.

The root level generator doesn't account for additional nested generators yet. I could add that by doing is_array($item) and the call the recursive placeholder logic.

Link to first PR that introduced StreamedJsonResponse: #47709

Also something I noticed is I only got intermediate output, when adding a flush() call after each item has been echo'd (with a sleep(1) after each item to see it output the parts individually). Edit: I see the class' PhpDoc describes this and it's probably expected to be done in userland implementations.

@derrabus
Copy link
Member

derrabus commented Sep 3, 2023

Thank you. Please be aware that we never merge new features without any tests.

@Jeroeny
Copy link
Contributor Author

Jeroeny commented Sep 4, 2023

@derrabus Thanks for the hint, added tests.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Please add a line about this to the changelog of the component.

@Jeroeny
Copy link
Contributor Author

Jeroeny commented Sep 14, 2023

Added the changelog entry

@fabpot
Copy link
Member

fabpot commented Oct 1, 2023

Thank you @Jeroeny.

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.

5 participants