From a80b07e48b223c1b8bc4b0b32cc0f020e46e3ef3 Mon Sep 17 00:00:00 2001 From: Gregor MacLennan Date: Fri, 27 Aug 2021 14:43:58 +0100 Subject: [PATCH 1/3] fix: don't cache icons between restarts of the app --- src/frontend/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/api.js b/src/frontend/api.js index 821e4927e..22df221d1 100644 --- a/src/frontend/api.js +++ b/src/frontend/api.js @@ -563,7 +563,7 @@ export function Api({ // Some devices are @4x or above, but we only generate icons up to @3x // Also we don't have @1.5x, so we round it up const roundedRatio = Math.min(Math.ceil(pixelRatio), 3); - return `${BASE_URL}presets/default/icons/${iconId}-medium@${roundedRatio}x.png`; + return `${BASE_URL}presets/default/icons/${iconId}-medium@${roundedRatio}x.png?{startupTime}`; }, // Return the url for a media attachment From fa4010fea4a3bc5c09e5a2dc991f66b0bc2e4ec6 Mon Sep 17 00:00:00 2001 From: Gregor MacLennan Date: Sat, 28 Aug 2021 10:44:33 +0100 Subject: [PATCH 2/3] fix typo --- src/frontend/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frontend/api.js b/src/frontend/api.js index 22df221d1..347693b84 100644 --- a/src/frontend/api.js +++ b/src/frontend/api.js @@ -563,7 +563,7 @@ export function Api({ // Some devices are @4x or above, but we only generate icons up to @3x // Also we don't have @1.5x, so we round it up const roundedRatio = Math.min(Math.ceil(pixelRatio), 3); - return `${BASE_URL}presets/default/icons/${iconId}-medium@${roundedRatio}x.png?{startupTime}`; + return `${BASE_URL}presets/default/icons/${iconId}-medium@${roundedRatio}x.png?${startupTime}`; }, // Return the url for a media attachment From b8ec6339da251e3c5e18b41911c013cc4b464dea Mon Sep 17 00:00:00 2001 From: Gregor MacLennan Date: Sat, 28 Aug 2021 10:53:30 +0100 Subject: [PATCH 3/3] Reset cache when new config is imported --- src/frontend/api.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/frontend/api.js b/src/frontend/api.js index 347693b84..9042fb78b 100644 --- a/src/frontend/api.js +++ b/src/frontend/api.js @@ -163,11 +163,11 @@ export function Api({ }) { let status: ServerStatus = STATUS.IDLE; let timeoutId: TimeoutID; - // We append this to requests for presets and map styles, in order to override - // the local static server cache whenever the app is restarted. NB. sprite, - // font, and map tile requests might still be cached, only changes in the map - // style will be cache-busted. - const startupTime = Date.now(); + // We append this to requests for presets, icons and map styles, in order to + // override the local static server cache whenever the app is restarted. NB. + // sprite, font, and map tile requests might still be cached, only changes in + // the map style will be cache-busted. + let startupTime = Date.now(); const req = ky.extend({ prefixUrl: baseUrl, @@ -456,8 +456,12 @@ export function Api({ function done(err) { clearTimeout(timeoutId); - if (err) reject(err); - else resolve(); + if (err) return reject(err); + // startupTime is use for cache-busting. When we replace the + // config we want the cache to be reset so that icons with the + // same name are not cached + startupTime = Date.now(); + resolve(); } }) );