Skip to content

perf(cron): Batch process temporary upload cleanup #39742

@himanshu2006

Description

@himanshu2006

Proposed changes
This PR optimizes the temporaryUploadCleanup cron job by replacing sequential execution with fault-tolerant batch processing.

Key Improvements:

  1. Memory & Connection Safety: Added a BATCH_SIZE of 50 to prevent the system from attempting to delete thousands of files simultaneously if a large backlog of temporary files expires at once.
  2. Fault Tolerance (Promise.allSettled): Replaced the sequential for await loop with Promise.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.
  3. 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

  1. Upload several temporary files.
  2. Trigger the temporaryUploadCleanup cron job.
  3. Verify files are successfully batch-deleted without throwing unhandled promise rejections if a file is manually removed from the storage bucket beforehand.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: featurePull requests that introduces new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions