Skip to content

[6.x] Look up a submission's form by handle - #16163

Open
duncanmcclean wants to merge 1 commit into
6.xfrom
submission-form-lookup
Open

duncanmcclean wants to merge 1 commit into
6.xfrom
submission-form-lookup

Conversation

@duncanmcclean

Copy link
Copy Markdown
Member

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 Form instance in its $form property. 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::$form is now private and holds the form's handle.
  • form() resolves the form with Blink::once("form-{$handle}"). Passing a Form instance to form() stores its handle and puts the instance in Blink, so the same instance comes back within a request.
  • $submission->form still returns the Form through __get().
  • Form::save() forgets the Blink key, like Collection::save() does.
  • The submissions store no longer calls Form::find() for every file.

Submissions serialized before this change (eg. queued jobs) still hold a Form instance, so form() 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

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant