Skip to content

R2 search endpoint loads all objects into memory #6

Description

@dotsdl

Problem

The /api/r2/search route handler calls listAllObjects, which paginates through every S3 object under a given prefix and loads them all into a JS array, then filters by filename in JS:

const objects = await listAllObjects(s3Client, bucket, prefix);
const matches = objects.filter(obj => { /* ... */ });

For a large bucket with many checkpoints, this will be slow, memory-intensive, and could time out on the server.

Suggested fix

  • Add a result count limit to listAllObjects (stop paginating after N objects).
  • Encourage callers to push the prefix as deep as possible before listing to reduce the search space.
  • Consider whether a different S3 access pattern (e.g., constructing known key paths directly rather than searching) could avoid the full listing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions