Skip to content

Commit

Permalink
🐛 fix explorer view indexing when metadata is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed Jan 31, 2025
1 parent 3e05a9b commit f6bbdbe
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions baker/algolia/utils/explorerViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,14 +470,13 @@ async function enrichWithTableData(
return enrichedRecords
}

function enrichRecordWithIndicatorData(
async function enrichRecordWithIndicatorData(
record: IndicatorUnenrichedExplorerViewRecord,
indicatorMetadataDictionary: ExplorerIndicatorMetadataDictionary
): IndicatorEnrichedExplorerViewRecord {
const allEntityNames = at(
indicatorMetadataDictionary,
record.yVariableIds
).flatMap((meta) => meta.entityNames)
): Promise<IndicatorEnrichedExplorerViewRecord | undefined> {
const allEntityNames = at(indicatorMetadataDictionary, record.yVariableIds)
.filter(Boolean)
.flatMap((meta) => meta.entityNames)

const uniqueNonEmptyEntityNames = uniq(allEntityNames).filter(
(name): name is string => !!name
Expand All @@ -486,6 +485,13 @@ function enrichRecordWithIndicatorData(
const firstYIndicator = record.yVariableIds[0]

const indicatorInfo = indicatorMetadataDictionary[firstYIndicator]
if (!indicatorInfo) {
await logErrorAndMaybeCaptureInSentry({
name: "ExplorerViewIndicatorMissing",
message: `Explorer with slug "${record.explorerSlug}" has a view with missing indicator metadata: ${record.viewQueryParams}.`,
})
return
}

const viewTitle =
record.viewTitle ||
Expand All @@ -505,16 +511,16 @@ function enrichRecordWithIndicatorData(
}
}

const enrichWithIndicatorMetadata = async (
async function enrichWithIndicatorMetadata(
indicatorBaseRecords: IndicatorUnenrichedExplorerViewRecord[],
indicatorMetadataDictionary: ExplorerIndicatorMetadataDictionary
): Promise<IndicatorEnrichedExplorerViewRecord[]> => {
return indicatorBaseRecords.map((indicatorBaseRecord) =>
): Promise<IndicatorEnrichedExplorerViewRecord[]> {
return pMap(indicatorBaseRecords, (indicatorBaseRecord) =>
enrichRecordWithIndicatorData(
indicatorBaseRecord,
indicatorMetadataDictionary
)
)
).then((r) => r.filter(Boolean) as IndicatorEnrichedExplorerViewRecord[])
}

function processSubtitles(
Expand Down Expand Up @@ -658,6 +664,7 @@ export const getExplorerViewRecordsForExplorer = async (
indicatorBaseRecords,
trx
)

console.log("Fetched indicator metadata for explorer", slug)

const enrichedIndicatorRecords = await enrichWithIndicatorMetadata(
Expand Down Expand Up @@ -739,6 +746,7 @@ export const getExplorerViewRecords = async (
console.log("(Skipping grapher views)")
}
const publishedExplorersWithTags = await getExplorersWithInheritedTags(trx)
// .then((es) => es.filter((e) => e.slug === "covid"))
const pageviews = await getAnalyticsPageviewsByUrlObj(trx)

const explorerAdminServer = new ExplorerAdminServer(GIT_CMS_DIR)
Expand Down

0 comments on commit f6bbdbe

Please sign in to comment.