Skip to content

Commit

Permalink
Merge pull request #68 from opentripplanner/dev
Browse files Browse the repository at this point in the history
Bug fix release
  • Loading branch information
landonreed authored Jul 2, 2019
2 parents 562fc08 + 9e10f35 commit 646fa12
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions lib/actions/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ query stopQuery($stopId: [String]) {
findStopResponse,
findStopError,
{
// find stop should not be throttled since it can make quite frequent
// updates when fetching stop times for a stop
noThrottle: true,
serviceId: 'stops',
rewritePayload: (payload) => {
// convert pattern array to ID-mapped object
Expand Down Expand Up @@ -715,17 +718,19 @@ function createQueryAction (endpoint, responseAction, errorAction, options = {})
url = `${api.host}${api.port ? ':' + api.port : ''}${api.path}/${endpoint}`
}

// don't make a request to a URL that has already seen the same request
// within the last 10 seconds
const throttleKey = options.fetchOptions
? `${url}-${hashObject(options.fetchOptions)}`
: url
if (throttledUrls[throttleKey] && throttledUrls[throttleKey] > now() - TEN_SECONDS) {
// URL already had a request within last 10 seconds, warn and exit
console.warn(`Request throttled for url: ${url}`)
return
} else {
throttledUrls[throttleKey] = now()
if (!options.noThrottle) {
// don't make a request to a URL that has already seen the same request
// within the last 10 seconds
const throttleKey = options.fetchOptions
? `${url}-${hashObject(options.fetchOptions)}`
: url
if (throttledUrls[throttleKey] && throttledUrls[throttleKey] > now() - TEN_SECONDS) {
// URL already had a request within last 10 seconds, warn and exit
console.warn(`Request throttled for url: ${url}`)
return
} else {
throttledUrls[throttleKey] = now()
}
}
let payload
try {
Expand Down

0 comments on commit 646fa12

Please sign in to comment.