storage-js
storage-js copied to clipboard
storage bucket list with limit and sortBy limits by natural order
Bug report
If that's a bug i'm not sure it's in supabase-js
Describe the bug
supabase.storage.from(<bucket>).list
calls with both limit and sortBy don't limit according to order
(as if the items are first fetched and only then sorted)
To Reproduce
these three calls (only difference is limit) produced different results in chrome dev tools console
await supabase.storage.from(<bucket>).list('',{sortBy:{column:'created_at',order:"desc"},limit:1}).then(r=>r.data[0].name)
(returned the item created first instead of last)
await supabase.storage.from(<bucket>).list('',{sortBy:{column:'created_at',order:"desc"},limit:2}).then(r=>r.data[0].name)
(returned the item created second)
await supabase.storage.from(<bucket>).list('',{sortBy:{column:'created_at',order:"desc"},limit:1000}).then(r=>r.data[0].name)
(returned the last item created - ok)
Expected behavior
should all return the latest item
System information
- OS: ubuntu 20
- Browser chrome
- Version of supabase-js: 1.21.0
Adding a bit more to this, the API first grabs every storage item in what looks like a random order and then organizes them by date. The limit property is only applied to the "grabbing" part and ends up returning only the lastest item inside that limited amount of items.
Two items:
The most recent item is 2022-01-28
100 Items:
The most recent item is 2022-01-29
Both are in the same storage bucket.
The expected would be for regardless of the limited amount, for the API to return always the most recent item.
This appears to have been fixed for a while now