Conversation
Signed-off-by: Hunter Achieng <achienghunter@gmail.com>
Signed-off-by: Hunter Achieng <achienghunter@gmail.com>
josephjclark
left a comment
There was a problem hiding this comment.
I've started a review but I need to put this down today as it sounds like you're not blocked on this.
I don't think the pagination rules are right though - so we need to take a real close look at that.
I also wonder if we need to add a callback like onPageDownloaded, and trigger that callback every time we finish a page. That makes it a lot easier for you to process data in batches, rather than downloading everything in one huge hit (this is a problem that affects a lot of our pagination APIs, but maybe this is an opportunity to start a new design pattern)
| * @function | ||
| * @param {string} path - Path to the resource | ||
| * @param {object} params - Object of query parameters to include in the request | ||
| * @options {number} [options.limit] - Optional limit to the number of records returned. By default, this is 10,000. |
There was a problem hiding this comment.
hmm. These docs are a little strange because they sort of imply that limit and offset are the only options. But you can put in any dhis2 query parameter here right?
I'll come back to this later and decide what to do
There was a problem hiding this comment.
Also offset is a page number, not an item offset? So it's saying "get me page 1000" not "get me items from item 1000"?
|
|
||
| export const getWithPagination = async (configuration, path, options = {}) => { | ||
| const { limit, offset = 1, ...requestOptions } = options; | ||
| const maxResults = requestOptions.query?.pageSize ?? limit ?? Infinity; |
There was a problem hiding this comment.
Max results != page size!
The two things are very different
Summary
Implemented pagination capabilities in the
get()function.Use
limitfor the exact number of items to be returned; default is 10000Use
offsetfor the page number to start with; default is 1Fixes #1546
AI Usage
Please disclose how you've used AI in this work (it's cool, we just want to
know!):
You can read more details in our
Responsible AI Policy
Review Checklist
Before merging, the reviewer should check the following items:
production? Is it safe to release?
dev only changes don't need a changeset.