From ddd50993a5b9412d59c1d7d6d0f4558b187d49c1 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Mon, 30 Nov 2020 10:53:55 +0100 Subject: [PATCH] cache pays --- app/javascript/components/shared/queryCache.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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; +}