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 rudimentary single-query rate limit #78

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,13 +471,18 @@ module.exports = class AbstractEndpoint {
}

// Execute multiple requests in parallel
_requestMany (urls, type = 'json') {
async _requestMany (urls, type = 'json') {
urls = urls.map(url => this._buildUrl(url))

/* istanbul ignore next */
const credentials = this.credentials ? 'include' : undefined

return this.fetch.many(urls, { type, credentials })
// rudimentry rate limit on single queries (e.g. api.items().all())
const BURST_LIMIT = 300 // hardcoded; 600 limit exposed in headers is inaccurate
const WAIT_TIME = 1 // lets-fetch adds wait time to sequential response rather than enforcing minimum sequential delay
const burst = await this.fetch.many(urls.slice(0, BURST_LIMIT - 1), { type, credentials })
const remaining = await this.fetch.many(urls.slice(BURST_LIMIT), { type, credentials, waitTime: WAIT_TIME })
return [...burst, ...remaining]
}

// Build the headers for localization and authentication
Expand Down