Skip to content

feat: Reuse live RequestStack objects during ?include serialization - #30

Draft
stephanschuler wants to merge 1 commit into
mainfrom
feat/provide-transient-entitys-to-property-mapper
Draft

feat: Reuse live RequestStack objects during ?include serialization#30
stephanschuler wants to merge 1 commit into
mainfrom
feat/provide-transient-entitys-to-property-mapper

Conversation

@stephanschuler

Copy link
Copy Markdown
Member

When serializing a TopLevel response with "?include=foo.bar", every relationship is mapped from a domain object to its type/id identifier and back to a domain object while the RequestStack is traversed. Each "identifier to domain object" step goes through the property mapper, which re-materializes the entity via Doctrine — adding a database round-trip, or at least requiring the object to be present in the persistence unit of work.

This adds a RequestStackRegistry singleton that holds weak references to all active RequestStack objects. Each RequestStack registers itself on creation and indexes the resources it holds by type and id. When an entity has to be reconstructed from an identifier — both in RequestStack::pushIdentifier() and in the schema-based entity type converter — the registry is consulted first and an already-loaded object is reused.

This avoids the redundant Doctrine lookup and preserves object identity across (nested) serialization passes. As the registry only keeps weak references, finished RequestStacks are garbage-collected normally.

When serializing a TopLevel response with "?include=foo.bar", every
relationship is mapped from a domain object to its type/id identifier
and back to a domain object while the RequestStack is traversed. Each
"identifier to domain object" step goes through the property mapper,
which re-materializes the entity via Doctrine — adding a database
round-trip, or at least requiring the object to be present in the
persistence unit of work.

This adds a RequestStackRegistry singleton that holds weak references
to all active RequestStack objects. Each RequestStack registers itself
on creation and indexes the resources it holds by type and id. When an
entity has to be reconstructed from an identifier — both in
RequestStack::pushIdentifier() and in the schema-based entity type
converter — the registry is consulted first and an already-loaded
object is reused.

This avoids the redundant Doctrine lookup and preserves object
identity across (nested) serialization passes. As the registry only
keeps weak references, finished RequestStacks are garbage-collected
normally.
@stephanschuler
stephanschuler marked this pull request as ready for review June 30, 2026 22:41
@stephanschuler
stephanschuler requested a review from Copilot June 30, 2026 22:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@stephanschuler
stephanschuler marked this pull request as draft July 1, 2026 01:06
@paxuclus
paxuclus requested a review from Copilot July 1, 2026 06:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread Classes/Netlogix/JsonApiOrg/Resource/RequestStackRegistry.php
Comment thread Classes/Netlogix/JsonApiOrg/Resource/RequestStack.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants