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.
Problem
The
/api/r2/searchroute handler callslistAllObjects, which paginates through every S3 object under a given prefix and loads them all into a JS array, then filters by filename in JS:For a large bucket with many checkpoints, this will be slow, memory-intensive, and could time out on the server.
Suggested fix
listAllObjects(stop paginating after N objects).