Skip to content

perf: ensure deepCopy in beforeValidate hook does not run unnecessarily for rest and graphQL API - #10666

Merged
AlessioGr merged 2 commits into
mainfrom
perf/beforevalidate-deepcopy
Jan 20, 2025
Merged

AlessioGr merged 2 commits into
mainfrom
perf/beforevalidate-deepcopy

Conversation

@AlessioGr

@AlessioGr AlessioGr commented Jan 19, 2025 •

Copy link
Copy Markdown
Member

Previously, the beforeValidate hook was deepCopying input data. This indirectly ensured that the passed input data was not mutated.

E.g., if you run the payload.create local API, you do not want that to mutate the data object that is passed as an argument. This will create issues if you attempt to use it multiple times.

This PR moves the deepCopy logic from the beforeValidate hook to the start of the local API operation. This ensures that

  • Input data is intentionally copied at the beginning which makes more sense. Comment was added to explain why
  • GraphQL and Rest operations are now faster, as we don't need to ensure that the input data is not mutated for those => deepCopy only runs for local API

@AlessioGr AlessioGr changed the title perf: remove unnecessary deepCopy in beforeValidate hook perf: ensure deepCopy in beforeValidate hook does not run unnecessarily for rest and graphQL API Jan 19, 2025
@AlessioGr
AlessioGr requested a review from DanRibbens January 19, 2025 05:47
@AlessioGr
AlessioGr merged commit b69fe99 into main Jan 20, 2025
@AlessioGr
AlessioGr deleted the perf/beforevalidate-deepcopy branch January 20, 2025 19:35
@github-actions

Copy link
Copy Markdown
Contributor

🚀 This is included in version v3.18.0

kendelljoseph pushed a commit that referenced this pull request Feb 21, 2025
…ly for rest and graphQL API (#10666)

Previously, the beforeValidate hook was deepCopying input data. This
indirectly ensured that the passed input data was not mutated.

E.g., if you run the `payload.create` local API, you do not want that to
mutate the `data` object that is passed as an argument. This will create
issues if you attempt to use it multiple times.


This PR moves the deepCopy logic from the beforeValidate hook to the
start of the local API operation. This ensures that
- Input data is intentionally copied at the beginning which makes more
sense. Comment was added to explain why
- GraphQL and Rest operations are now faster, as we don't need to ensure
that the input data is not mutated for those => deepCopy only runs for
local API
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.

2 participants