From bcdf157faf857882eedab9765af53ec66957e2fb Mon Sep 17 00:00:00 2001 From: jhmullen Date: Thu, 19 May 2022 19:24:16 -0400 Subject: [PATCH] makes infinitesimal perf improvement --- packages/cms/src/api/searchRoute.js | 3 ++- packages/cms/src/cache/searchIndexByLocale.js | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/cms/src/api/searchRoute.js b/packages/cms/src/api/searchRoute.js index 785ee8068..d9b47d8b7 100644 --- a/packages/cms/src/api/searchRoute.js +++ b/packages/cms/src/api/searchRoute.js @@ -11,6 +11,7 @@ const {CANON_CMS_CUBES, CANON_CMS_MINIMUM_ROLE, OLAP_PROXY_SECRET, CANON_CMS_LUN process.env; const verbose = yn(process.env.CANON_CMS_LOGGING); +const useLUNR = yn(CANON_CMS_LUNR); let Base58, flickr, sharp, storage; if (process.env.FLICKR_API_KEY) { const Flickr = require("flickr-sdk"); @@ -578,7 +579,7 @@ module.exports = function(app) { let contentIds = []; const {searchIndexByLocale} = app.settings.cache; - if (yn(CANON_CMS_LUNR) && searchIndexByLocale[locale]) { + if (useLUNR && searchIndexByLocale[locale]) { const terms = query.split(" ").map(d => `+${d}~1*`).join(" "); const lunrResults = searchIndexByLocale[locale].search(terms); contentIds = lunrResults.map(d => d.ref); diff --git a/packages/cms/src/cache/searchIndexByLocale.js b/packages/cms/src/cache/searchIndexByLocale.js index e1c468971..dbf673457 100644 --- a/packages/cms/src/cache/searchIndexByLocale.js +++ b/packages/cms/src/cache/searchIndexByLocale.js @@ -8,7 +8,9 @@ const {CANON_LANGUAGES, CANON_CMS_LUNR} = process.env; const locales = CANON_LANGUAGES ? CANON_LANGUAGES.split(",").filter(d => whitelist.includes(d)) : []; -for (const locale of locales.filter(d => d !== "en")) { +const nonEnLocales = locales.filter(d => d !== "en"); + +for (const locale of nonEnLocales) { require(`lunr-languages/lunr.${locale}`)(lunr); }