Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@vercel/blob: pagination with limit: N, N <1000 #835

Open
gheorghemolnar opened this issue Feb 25, 2025 · 2 comments
Open

@vercel/blob: pagination with limit: N, N <1000 #835

gheorghemolnar opened this issue Feb 25, 2025 · 2 comments

Comments

@gheorghemolnar
Copy link

gheorghemolnar commented Feb 25, 2025

I'm currently evaluating the @vercel/storage blob in my project and I came across this pottential issue while using list with pagination.

Context:

  • I've set up the token
  • a total of 6 files uploaded on my project storage
  • using the list with limit of 2

Problem Description:

  • i'm issuing the first request with no cursor

    • I get the first 2 results, with: 'cursor' populated with a string and 'hasMore': true
  • on the 2nd request, I put the cursor and its previously received value, in query

    • I get the same first results il 'files', with 'cursor' populated with a different string and 'hasMore': true

The behaviour of the 2nd request is happening for the followings request:
- cursor populated every time with a differrent string value
- hasMore is polpulated with true, event if it should return hasMore: false (ex. on the 4th time call of the 'limit' function).

I can get all the results (6 of them), only if I don't specify the limit in the optional parameters of the limit function.
Can you give me some insights on this ?
Thank you !

@vvo
Copy link
Member

vvo commented Feb 25, 2025

Hey there @gheorghemolnar I just tested your setup and could not generate the same issues.

Here's my script:

import { list } from "@vercel/blob";

async function listFilesTwoByTwo() {
  let hasMore = true;
  let cursor;
  const limit = 2;

  while (hasMore) {
    const {
      blobs,
      cursor: newCursor,
      hasMore: newHasMore,
    } = await list({ limit, cursor });

    console.log(blobs.length, typeof newCursor, newHasMore);

    cursor = newCursor;
    hasMore = newHasMore;
  }
}

listFilesTwoByTwo();

And the result:

> BLOB_READ_WRITE_TOKEN="xxx" node test.js
2 string true # Good
2 string true
2 string true
2 string true
2 string true
2 string true
2 string true
2 string true
1 undefined false # Good

Can you confirm my script output is the one you would expect? And check why you're getting a different result, thanks!

@gheorghemolnar
Copy link
Author

gheorghemolnar commented Feb 25, 2025

Hi @vvo , thank you for your quick response.
Indeed, I've tested the example, and it's working properly.

But in my case, i'm not using it in one loop, that gets all the results.

import { list } from "@vercel/blob";

let cursorPrevious = ""

async function listFilesTwoByTwo(cursor = "") {
    const limit = 2;
    const {
      blobs,
      cursor: newCursor,
      hasMore: newHasMore,
    } = await list({ limit, cursor });

    return {
        cursor:newCursor,
        hasMore:newHasMore
    }
}


listFilesTwoByTwo(cursorPrevious);            // here I get {cursor: 'new value 01', hasMore: true}
listFilesTwoByTwo(cursorPrevious);            // here I get {cursor: 'new value 02', hasMore: true}
... 
4th times
....
listFilesTwoByTwo(cursorPrevious);             // here I get {cursor: 'new value 0X', hasMore: true}     
                                                                    // I would expect hasMore: false, and maybe cursor: ""

Thank you again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants