diff --git a/app/javascript/components/shared/queryCache.js b/app/javascript/components/shared/queryCache.js index 6809c0473..2e474a5f4 100644 --- a/app/javascript/components/shared/queryCache.js +++ b/app/javascript/components/shared/queryCache.js @@ -33,8 +33,7 @@ function buildOptions() { async function defaultQueryFn(scope, term) { if (scope == 'pays') { - const pays = await fetch('/pays.json').then((response) => response.json()); - return matchSorter(pays, term, { keys: ['nom'] }); + return matchSorter(await getPays(), term, { keys: ['nom'] }); } const url = buildURL(scope, term); @@ -43,3 +42,11 @@ async function defaultQueryFn(scope, term) { promise.cancel = () => controller && controller.abort(); return promise; } + +let paysCache; +async function getPays() { + if (!paysCache) { + paysCache = await fetch('/pays.json').then((response) => response.json()); + } + return paysCache; +}