RocketChat / RocketChat/Rocket.Chat
perf(cron): Batch process temporary upload cleanup
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 46.1k
- Forks
- 13.9k
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 130
Description
Proposed changes
This PR optimizes the temporaryUploadCleanup cron job by replacing sequential execution with fault-tolerant batch processing.
Key Improvements:
- Memory & Connection Safety: Added a
BATCH_SIZEof 50 to prevent the system from attempting to delete thousands of files simultaneously if a large backlog of temporary files expires at once. - Fault Tolerance (
Promise.allSettled): Replaced the sequentialfor awaitloop withPromise.allSettled. Previously, if a single file deletion failed (e.g., file already missing from storage), the entire cron job would crash, leaving the remaining expired files in the database. Now, the process is resilient and will complete the remaining deletions even if individual promises reject. - Optimized Store Reference: Lifted
FileUpload.getStore('Uploads')out of the loop to prevent unnecessary redundant lookups.
Issue(s)
Proactive performance and resilience optimization for backend background jobs.
Steps to test or reproduce
- Upload several temporary files.
- Trigger the
temporaryUploadCleanupcron job. - Verify files are successfully batch-deleted without throwing unhandled promise rejections if a file is manually removed from the storage bucket beforehand.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the temporaryUploadCleanup cron job and inspect how FileUpload.getStore('Uploads') and expired temporary files are currently processed. Exercise the job with several temporary files, including one removed from storage beforehand; done means cleanup continues after an individual deletion failure, processes files in batches of 50, and avoids unhandled promise rejections.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend, performance
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100