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

Add pagination with cursor #7637

Open
3 tasks done
mtrezza opened this issue Oct 15, 2021 · 2 comments
Open
3 tasks done

Add pagination with cursor #7637

mtrezza opened this issue Oct 15, 2021 · 2 comments
Labels
bounty:$250 Bounty applies for fixing this issue (Parse Bounty Program) type:feature New feature or improvement of existing feature

Comments

@mtrezza
Copy link
Member

mtrezza commented Oct 15, 2021

New Feature / Enhancement Checklist

Current Limitation

Query results pagination can currently only be achieved by using limit and skip. A MongoDB query however also returns a cursor that can be used to paginate through query results.

Feature / Enhancement Description

  • Add the query result cursor to response of a query as meta data.
  • Add a methods to interact with the cursor.

For example:

let q = new Parse.Query();
q.equalTo(...);
const response = await q.find();

const page1 = response.results;
const cursor = response.cursor;

q = Parse.Query.fromCursor(cursor);
q.skip(100);
q.limit(100);
const page2 = await q.find();

Or alternatively introduce an entirely new command set for cursor operations, for example:

c = Parse.QueryCursor(cursor);
c.moveToPosition(100);
const page2 = await c.return(100);

Returning meta data together with the response is related to a pending change of the response object for a sustainable modification of the response JSON structure, see #7440 (comment). Returning a cursor together with results is one use case that justifies the change of the query response from a ParseObject array to this more versatile form:

{
  results: [...],
  meta: {
    cursor: ...,
    explain: ...
  }
}

Example Use Case

See the current challenge of pagination in Parse Dashboard in parse-community/parse-dashboard#1551.

Alternatives / Workarounds

Paginate using limit and skip with the major downside of each pagination request issuing a new query instead of using the existing cached query results on the database side. The other challenge is that each new query is done over a potentially changing data set, so the limit / skip parameters become inaccurate.

@parse-github-assistant
Copy link

parse-github-assistant bot commented Oct 15, 2021

Thanks for opening this issue!

  • 🎉 We are excited about your ideas for improvement!

@mtrezza mtrezza added bounty:$50 Bounty applies for fixing this issue (Parse Bounty Program) type:feature New feature or improvement of existing feature labels Oct 15, 2021
@cbaker6
Copy link
Contributor

cbaker6 commented Jan 6, 2022

Cursor for postgres: https://www.postgresql.org/docs/current/plpgsql-cursors.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bounty:$250 Bounty applies for fixing this issue (Parse Bounty Program) type:feature New feature or improvement of existing feature
Projects
None yet
Development

No branches or pull requests

2 participants