Skip to content

Commit

Permalink
✨ improve getSlugsWithPublishedGdocsSuccessors
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed Jun 20, 2024
1 parent e1bfef4 commit 9382bc9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
17 changes: 4 additions & 13 deletions baker/SiteBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import {
import { getBakePath } from "@ourworldindata/components"
import { GdocAuthor, getMinimalAuthors } from "../db/model/Gdoc/GdocAuthor.js"
import { DATA_INSIGHTS_ATOM_FEED_NAME } from "../site/gdocs/utils.js"
import { getRedirectsFromDb } from "../db/model/Redirect.js"

type PrefetchedAttachments = {
linkedAuthors: DbEnrichedAuthor[]
Expand Down Expand Up @@ -510,28 +511,18 @@ export class SiteBaker {

private async bakePosts(knex: db.KnexReadonlyTransaction) {
if (!this.bakeSteps.has("wordpressPosts")) return
// TODO: the knex instance should be handed down as a parameter
const alreadyPublishedViaGdocsSlugsSet =
await db.getSlugsWithPublishedGdocsSuccessors(knex)
const redirectTargets = await db.knexRaw<{
source: string
target: string
}>(
knex,
`-- sql
SELECT source, target FROM redirects WHERE code = 301`
)
const redirects = await getRedirectsFromDb(knex)

const postsApi = await getPostsFromSnapshots(
knex,
undefined,
(postrow) =>
// Exclude posts that are already published via GDocs
!alreadyPublishedViaGdocsSlugsSet.has(postrow.slug) &&
// Exclude posts that are redirect targets
!redirectTargets.some(
(row) => row.source.slice(1) === postrow.slug
)
// Exclude posts that are redirect sources
!redirects.some((row) => row.source.slice(1) === postrow.slug)
)

await pMap(
Expand Down
3 changes: 1 addition & 2 deletions db/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ export const getSlugsWithPublishedGdocsSuccessors = async (
knex,
`-- sql
SELECT
p.slug,
p.type
p.slug
FROM
posts p
LEFT JOIN posts_gdocs g on
Expand Down

0 comments on commit 9382bc9

Please sign in to comment.