feat: stream large submission exports directly from db without memory… - #2123
Merged
RUKAYAT-CODER merged 4 commits intoJul 30, 2026
Merged
Conversation
|
@AbuJulaybeeb Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
Kindly resolve conflict |
AbuJulaybeeb
marked this pull request as draft
July 30, 2026 16:01
AbuJulaybeeb
marked this pull request as ready for review
July 30, 2026 16:14
Contributor
|
Thank you for contributing to the project. |
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.
closes #1971.
This PR addresses memory spikes caused by generating large submission exports for quests with thousands of participants by transitioning entirely away from offset-based, chunked data queries and removing memory buffering in our streaming service.
Changes:
True DB Streaming Cursors: Refactored getQueryIterator in StreamExportService to utilize TypeORM's native .stream() method. Previously, getQueryIterator achieved "chunking" via .skip(offset).take(chunkSize), which executes repeated offset queries causing degraded SQL performance for deep records and buffering arrays in memory.
Implement Network Backpressure: Rewrote streamAsCSV, streamAsJSONLines, and streamAsJSON in StreamExportService to evaluate the boolean return value from response.write(). If the underlying TCP buffer backs up (returns false), the stream now pauses via await new Promise(resolve => response.once('drain', resolve)) until the buffer clears, capping concurrency safely.
Testing & Benchmarks: Updated stream-export.service.spec.ts mocks to handle the new once and backpressure assertions. A new benchmark script (BackEnd/scripts/benchmark-export.ts) was added to demonstrate stable memory (less than a few MBs of variance) regardless of how large the requested dataset is.