Cache keys should not be the same (#1223)

Fix the cache bug introduced in #1186 that blocked today's deploy.
This commit is contained in:
Paul Melnikow
2017-10-29 22:11:10 -04:00
committed by GitHub
parent 9d84d2fec1
commit 090454a828
2 changed files with 24 additions and 3 deletions

View File

@@ -97,7 +97,7 @@ function handleRequest (handlerOptions) {
// Use sindresorhus query-string because it sorts the keys, whereas the
// builtin querystring module relies on the iteration order.
const stringified = queryString.stringify(filteredQueryParams);
const cacheIndex = `match[0]?${stringified}`;
const cacheIndex = `${match[0]}?${stringified}`;
// Should we return the data right away?
const cached = requestCache.get(cacheIndex);
@@ -199,5 +199,7 @@ function clearRequestCache() {
module.exports = {
handleRequest,
clearRequestCache
clearRequestCache,
// Expose for testing.
_requestCache: requestCache
};

View File

@@ -8,7 +8,8 @@ const analytics = require('./analytics');
const { makeBadgeData: getBadgeData } = require('./badge-data');
const {
handleRequest,
clearRequestCache
clearRequestCache,
_requestCache
} = require('./request-handler');
const baseUri = `http://127.0.0.1:${config.port}`;
@@ -113,6 +114,24 @@ describe('The request handler', function() {
'/testing/123.svg?foo=2'
).then(() => { assert.equal(handlerCallCount, 1); });
});
describe('the cache key', function () {
const expectedCacheKey = '/testing/123.json?colorB=123&label=foo';
it('should match expected and use canonical order - 1', function () {
return fetch(`${baseUri}/testing/123.json?colorB=123&label=foo`)
.then(res => {
assert.ok(res.ok);
assert.deepEqual([..._requestCache.cache.keys()], [expectedCacheKey]);
});
});
it('should match expected and use canonical order - 2', function () {
return fetch(`${baseUri}/testing/123.json?label=foo&colorB=123`)
.then(res => {
assert.ok(res.ok);
assert.deepEqual([..._requestCache.cache.keys()], [expectedCacheKey]);
});
});
});
});
describe('custom query parameters', function() {