Skip to content

Commit

Permalink
refactor: filter down narrativeViewsInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber committed Dec 17, 2024
1 parent 6d74882 commit d03a0e4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 9 additions & 3 deletions baker/SiteBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export class SiteBaker {
_prefetchedAttachmentsCache: PrefetchedAttachments | undefined = undefined
private async getPrefetchedGdocAttachments(
knex: db.KnexReadonlyTransaction,
picks?: [string[], string[], string[], string[], string[]]
picks?: [string[], string[], string[], string[], string[], string[]]
): Promise<PrefetchedAttachments> {
if (!this._prefetchedAttachmentsCache) {
console.log("Prefetching attachments...")
Expand Down Expand Up @@ -490,6 +490,7 @@ export class SiteBaker {
imageFilenames,
linkedGrapherSlugs,
linkedExplorerSlugs,
linkedNarrativeChartNames,
] = picks
const linkedDocuments = pick(
this._prefetchedAttachmentsCache.linkedDocuments,
Expand Down Expand Up @@ -538,8 +539,10 @@ export class SiteBaker {
this._prefetchedAttachmentsCache.linkedAuthors.filter(
(author) => authorNames.includes(author.name)
),
narrativeViewsInfo:
this._prefetchedAttachmentsCache.narrativeViewsInfo, // TODO: Filter
narrativeViewsInfo: pick(
this._prefetchedAttachmentsCache.narrativeViewsInfo,
linkedNarrativeChartNames
),
}
}
return this._prefetchedAttachmentsCache
Expand Down Expand Up @@ -631,6 +634,7 @@ export class SiteBaker {
publishedGdoc.linkedImageFilenames,
publishedGdoc.linkedChartSlugs.grapher,
publishedGdoc.linkedChartSlugs.explorer,
publishedGdoc.linkedNarrativeChartNames,
])
publishedGdoc.donors = attachments.donors
publishedGdoc.linkedAuthors = attachments.linkedAuthors
Expand Down Expand Up @@ -889,6 +893,7 @@ export class SiteBaker {
dataInsight.linkedImageFilenames,
dataInsight.linkedChartSlugs.grapher,
dataInsight.linkedChartSlugs.explorer,
dataInsight.linkedNarrativeChartNames,
])
dataInsight.linkedDocuments = attachments.linkedDocuments
dataInsight.imageMetadata = {
Expand Down Expand Up @@ -962,6 +967,7 @@ export class SiteBaker {
publishedAuthor.linkedImageFilenames,
publishedAuthor.linkedChartSlugs.grapher,
publishedAuthor.linkedChartSlugs.explorer,
publishedAuthor.linkedNarrativeChartNames,
])

// We don't need these to be attached to the gdoc in the current
Expand Down
14 changes: 12 additions & 2 deletions db/model/Gdoc/GdocBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@ export class GdocBase implements OwidGdocBaseInterface {
return { grapher: [...grapher], explorer: [...explorer] }
}

get linkedNarrativeChartNames(): string[] {
const filteredLinks = this.links
.filter((link) => link.linkType === "narrative-chart")
.map((link) => link.target)

return filteredLinks
}

get hasAllChartsBlock(): boolean {
let hasAllChartsBlock = false
for (const enrichedBlockSource of this.enrichedBlockSources) {
Expand Down Expand Up @@ -703,8 +711,10 @@ export class GdocBase implements OwidGdocBaseInterface {
async loadNarrativeViewsInfo(
knex: db.KnexReadonlyTransaction
): Promise<void> {
// TODO: Filter down to only those that are used in the Gdoc
const result = await getNarrativeViewsInfo(knex)
const result = await getNarrativeViewsInfo(
knex,
this.linkedNarrativeChartNames
)
this.narrativeViewsInfo = keyBy(result, "name")
}

Expand Down

0 comments on commit d03a0e4

Please sign in to comment.