-
Notifications
You must be signed in to change notification settings - Fork 13.5k
perf(cron): Batch process temporary upload cleanup #39742
Copy link
Copy link
Open
Labels
type: featurePull requests that introduces new featurePull requests that introduces new feature
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type: featurePull requests that introduces new featurePull requests that introduces new feature