storage-js icon indicating copy to clipboard operation
storage-js copied to clipboard

storage bucket list with limit and sortBy limits by natural order

Open asafamr opened this issue 3 years ago • 2 comments

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

asafamr avatar Jul 29 '21 16:07 asafamr

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: image The most recent item is 2022-01-28

100 Items: image 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.

rortan134 avatar Jan 29 '22 16:01 rortan134

This appears to have been fixed for a while now

rortan134 avatar Nov 29 '22 21:11 rortan134