Skip to content

Commit

Permalink
perf(algolia): optimize chart indexing code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber committed Apr 10, 2024
1 parent 6fba963 commit 5aa3cd9
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions baker/algolia/indexChartsToAlgolia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ const computeScore = (record: Omit<ChartRecord, "score">): 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",
Expand All @@ -41,7 +43,7 @@ const processAvailableEntities = (availableEntities: string[] | null) => {
availableEntities,
[
(entityName) =>
countriesWithVariantNames.includes(
countriesWithVariantNames.has(
removeTrailingParenthetical(entityName)
),
(entityName) => entityName,
Expand Down

0 comments on commit 5aa3cd9

Please sign in to comment.