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

Paginate data with query cursors #16

Open
mnightingale opened this issue Mar 25, 2022 · 0 comments
Open

Paginate data with query cursors #16

mnightingale opened this issue Mar 25, 2022 · 0 comments

Comments

@mnightingale
Copy link
Contributor

As I understand it currently queries don't really paginate, the query limit is just continuously increased and any duplicate ids are ignored.
i.e. it queries for 20 items, then 40, 60, 80, etc.
In some cases this can cause a lot of document reads.

Would a PR be welcome that uses the firestore pagination methods Paginate data with query cursors ?

I don't think this would cause an issue, startAt requires a orderBy but so does limit.

I was thinking something like:

stepLimit + 1 because I choose to use startAt rather than startAfter in case there are multiple items with the same order key and I want stepLimit extra items.

let queryLimited = ref.current

if (after !== null) {
  queryLimited = queryLimited.startAt(after).limit(stepLimit + 1)
} else {
  queryLimited = queryLimited.limit(stepLimit)
}
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