Repository navigation
[6.x] Look up a submission's form by handle - #16163
Open
duncanmcclean wants to merge 1 commit into
Open
duncanmcclean wants to merge 1 commit into
duncanmcclean wants to merge 1 commit into
Conversation
stops every submission carrying its own copy of the form's fields. Amp-Thread-ID: https://ampcode.com/threads/T-01a23905-61d0-77bd-b0ef-bf8acb07974b Co-authored-by: Amp <amp@ampcode.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request fixes an issue where loading form submissions on a site with lots of them could exhaust PHP's memory limit.
This was happening because every submission held its own
Forminstance in its$formproperty. Since Forms 2 keeps fields inline in the form's YAML, each of those instances carried a full copy of the form's fields. That copy was also serialized into every submission's Stache cache entry, so loading 5,000 submissions meant 5,000 copies of the form.This PR fixes it by having submissions look up their form by handle, the same way entries look up their collection:
Submission::$formis nowprivateand holds the form's handle.form()resolves the form withBlink::once("form-{$handle}"). Passing aForminstance toform()stores its handle and puts the instance in Blink, so the same instance comes back within a request.$submission->formstill returns theFormthrough__get().Form::save()forgets the Blink key, likeCollection::save()does.Form::find()for every file.Submissions serialized before this change (eg. queued jobs) still hold a
Forminstance, soform()returns it as-is.In a sandbox with a 25-field form and 5,000 submissions, a cold
FormSubmission::find()went from a 231 MB peak to 38 MB. Each cached submission went from 8.3 KB to 1.6 KB.The other half of the issue (the form tag looking up submissions when there's no partial submission) is in a separate PR.
Amp thread: https://ampcode.com/threads/T-01a23905-61d0-77bd-b0ef-bf8acb07974b
Related: #16159