-
Notifications
You must be signed in to change notification settings - Fork 761
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 to search endpoints #583
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -235,13 +235,30 @@ class Requestable { | |
* @param {string} path - the path to request | ||
* @param {Object} options - the query parameters to include | ||
* @param {Requestable.callback} [cb] - the function to receive the data. The returned data will always be an array. | ||
* @param {Object[]} results - the partial results. This argument is intended for internal use only. | ||
* @return {Promise} - a promise which will resolve when all pages have been fetched | ||
* @deprecated This will be folded into {@link Requestable#_request} in the 2.0 release. | ||
*/ | ||
_requestAllPages(path, options, cb, results) { | ||
results = results || []; | ||
_requestAllPages(path, options, cb) { | ||
let manualPagination = false; | ||
if (typeof options.page !== 'undefined') { | ||
manualPagination = true; | ||
} | ||
|
||
return this._requestAllPagesHelper(path, options, cb, [], manualPagination); | ||
} | ||
|
||
/** | ||
* Perform the logic of fetching multiple pages | ||
* @private | ||
* @param {string} path - the path to request | ||
* @param {Object} options - the query parameters to include | ||
* @param {Requestable.callback} [cb] - the function to receive the data. The returned data will always be an array. | ||
* @param {Object[]} results - the partial results. This argument is intended for internal use only. | ||
* @param {boolean} manualPagination - the flag to decide if multiple pages should be fetched | ||
* @return {Promise} - a promise which will resolve when all pages have been fetched | ||
* @deprecated This will be folded into {@link Requestable#_request} in the 2.0 release. | ||
*/ | ||
_requestAllPagesHelper(path, options, cb, results, manualPagination) { | ||
return this._request('GET', path, options) | ||
.then((response) => { | ||
let thisGroup; | ||
|
@@ -256,19 +273,19 @@ class Requestable { | |
results.push(...thisGroup); | ||
|
||
const nextUrl = getNextPage(response.headers.link); | ||
if(nextUrl) { | ||
if(nextUrl && !manualPagination) { | ||
if (!options) { | ||
options = {}; | ||
} | ||
options.page = parseInt( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If someone can clarify this, I would appreciate it. Why does the page number need to be manually extracted and appended to the options?
Although this might just be a workaround for other endpoints, since I have't done exploration into how other endpoints paginate. |
||
nextUrl.match(/([&\?]page=[0-9]*)/g) | ||
.shift() | ||
.split('=') | ||
.pop() | ||
nextUrl.match(/([&\?]page=[0-9]*)/g) | ||
.shift() | ||
.split('=') | ||
.pop() | ||
); | ||
if (!(options && typeof options.page !== 'number')) { | ||
log(`getting next page: ${nextUrl}`); | ||
return this._requestAllPages(nextUrl, options, cb, results); | ||
return this._requestAllPagesHelper(nextUrl, options, cb, results, false); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if jsdoc understands how to reach into other files (Search.js). Let me know if this will be a problem.