Repository navigation
fix(cloudflare-r2-binding): paginate list and batch delete past 1000 objects - #881
debojyoti10CC wants to merge 1 commit into
Conversation
…objects getKeys now follows the list cursor while the result is truncated, and clear deletes in chunks of 1000 keys (the R2 per-call limit).
|
@debojyoti10CC is attempting to deploy a commit to the unjs Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
Bumping this in case it got buried. It is still ready for review, and I am happy to make any changes you would like. Thanks! |
Problem
getKeysandclearin thecloudflare-r2-bindingdriver callbinding.list()once. R2 returns at most 1000 objects per call, so anything beyond the first 1000 was silently ignored:getKeysreturned a truncated list andclearleft the remaining objects in place.Fix
getKeysnow loops on thecursorwhiletruncatedis true.cleardeletes the collected keys in chunks of 1000, sinceR2Bucket.deleteaccepts at most 1000 keys per call.Testing
Added
test/drivers/cloudflare-r2-binding-pagination.test.ts, which uses a fake bucket that pages 1000 at a time (2500 objects) and rejects deletes of more than 1000 keys. I put it in its own file because the existing R2 test file starts a wrangler platform proxy.Before the fix:
After:
oxlintandoxfmt --checkare clean for the changed files. I could not run the existing wrangler-based R2 test locally: it hung on my Windows machine.Fixes #880
Summary by CodeRabbit
Bug Fixes
Tests