From ce7b3e81e6b2d155c93fe082c83816ae116465af Mon Sep 17 00:00:00 2001 From: Marcel Gerber Date: Tue, 26 Mar 2024 09:23:24 +0100 Subject: [PATCH] perf(algolia): optimize chart indexing code a bit --- baker/algolia/indexChartsToAlgolia.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/baker/algolia/indexChartsToAlgolia.ts b/baker/algolia/indexChartsToAlgolia.ts index aec341e7fe5..8d2475ec7d7 100644 --- a/baker/algolia/indexChartsToAlgolia.ts +++ b/baker/algolia/indexChartsToAlgolia.ts @@ -23,12 +23,14 @@ const computeScore = (record: Omit): number => { return numRelatedArticles * 500 + views_7d } -const processAvailableEntities = (availableEntities: string[] | null) => { - if (!availableEntities) return [] - - const countriesWithVariantNames = countries +const countriesWithVariantNames = new Set( + countries .filter((country) => country.variantNames?.length || country.shortName) .map((country) => country.name) +) + +const processAvailableEntities = (availableEntities: string[] | null) => { + if (!availableEntities) return [] // Algolia is a bit weird with synonyms: // If we have a synonym "USA" -> "United States", and we search for "USA", @@ -41,7 +43,7 @@ const processAvailableEntities = (availableEntities: string[] | null) => { availableEntities, [ (entityName) => - countriesWithVariantNames.includes( + countriesWithVariantNames.has( removeTrailingParenthetical(entityName) ), (entityName) => entityName,