From e72c3fbc604bad4f6c056d07f2389c39c5d24505 Mon Sep 17 00:00:00 2001 From: Evan Siroky Date: Fri, 28 Jun 2019 17:48:16 -0700 Subject: [PATCH 1/2] fix(Stop Viewer): don't throttle stop time update requests --- lib/actions/api.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/actions/api.js b/lib/actions/api.js index 77be3becd..7a3196b00 100644 --- a/lib/actions/api.js +++ b/lib/actions/api.js @@ -337,6 +337,7 @@ query stopQuery($stopId: [String]) { findStopResponse, findStopError, { + noThrottle: true, serviceId: 'stops', rewritePayload: (payload) => { // convert pattern array to ID-mapped object @@ -715,17 +716,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 { From 813df5ad6c1eb9a6f34656b8f37dc9b9f7405fb3 Mon Sep 17 00:00:00 2001 From: Evan Siroky Date: Mon, 1 Jul 2019 15:11:29 -0700 Subject: [PATCH 2/2] refactor(api): add comment explaining why findStop query is not throttled --- lib/actions/api.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/actions/api.js b/lib/actions/api.js index 7a3196b00..64c0d94dd 100644 --- a/lib/actions/api.js +++ b/lib/actions/api.js @@ -337,6 +337,8 @@ 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) => {