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 API - list() - Filtering (before pagination) and possibly sorting too #794

Open
ADTC opened this issue Nov 15, 2024 · 0 comments

Comments

@ADTC
Copy link

ADTC commented Nov 15, 2024

In Blob API list() function, please add the ability to filter while maintaining pagination.

list({
  ...options
  filter: null | {
    // one or more of:
    sizeLessThan: number,
    sizeMoreThan: number,
    uploadedLaterThan: Date,
    uploadedEarlierThan: Date,
    pathname: string | Regex,
    contentType: string | string[] | Regex,
    contentDisposition: string | string[] | Regex,
    url: string | Regex,
    downloadUrl: string | Regex,
    cacheControl: string | string[] | Regex,
  }
})

Otherwise the workaround is quite clunky and doesn't work well with pagination. Suppose we need to show only images from a collection of media paginated 100 at a time. Maybe page 1 has only 67 images. Then the list() function will fetch 100 media and the UI displays 67 images on page 1. Then it fetches another 100 images on page 2, only to display maybe 33 images. Maybe page 3 has no images out of 100 media (misleading the user), then page 4 has 87 images out of 100 media.

I hope you get what I mean, and why "filtered, then paginated" results will be better.

I saw that sorting was refused citing technical limitations in #533 which has me worried that this request for filters could also be refused. In the issue, it was said that the:

underlying object storage technology we use doesn't have this feature (and most of them don't: aws s3 doesn't have it)

That is unfortunate, but I believe it could be overcome by having an in-between:

Client-side       Vercel Blob        Vercel Blob            Filtered,
list() call  --->  gets full  --->   applies sort  --->    sorted and
  issued          object list      filter/paginate          paginated
                from underlying           ^              results returned
                 storage tech.     (the in-between)         to client.

If Vercel will not provide this "in-between" natively (which could be hyperfast because it runs internally with the lowest latency), we'll have to build our own version of the "in-between" where sorting and filtering is desired (which wouldn't be as fast, because not only do we have to call list() to get complete blob object lists (file lists), we then also have to call head() each and every one of them to get the additional information (which is another gripe I have with list() because it's missing critical information which can only be obtained by a separate head() call). This has increased the development cost, time cost and network resource cost.

I hope you get the rationale for why it's better to build it in-house and expose it as filter and sort options in list() function.

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

1 participant