fix: inefficient form metadata query leading to excessive memory usage #5763
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.
Problem
We have been seeing very slow
formsg.submissions
operations which have very high db disk utilInitial suspicion was that this was due to download of large forms
Closes [8] Database read time spikes due to response downloads #3394
Solution
63e9b7e27e26fb0012795ca8
(200k small responses) and63e9d46e6d6d6f0012d14402
(20k large responses of >700KB each) on staging (log in using form team email, key in 1pw)./metadata
endpoint, which returns response metadata for storage mode submissions. This is triggered once the admin navigates to response tab.submission.server.model.ts
, the following code retrieves all submission documents corresponding to the form, stores it all in memory (or disk, becauseallowDiskUse(true)
), in order to count the number of responses. This led to excessive disk utilisation and slow query (seeNOTE
below).countDocuments
query.Existing code
Improvements:
Before & After Screenshots
BEFORE:
AFTER:
Tests