Skip to content

Commit

Permalink
🐛 fix baking-with-gdocs-successor filtering logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed Oct 26, 2023
1 parent 9afee98 commit 9bf2c09
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
12 changes: 2 additions & 10 deletions baker/SiteBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,8 @@ export class SiteBaker {

private async bakePosts() {
if (!this.bakeSteps.has("wordpressPosts")) return
// In the backporting workflow, the users create gdoc posts for posts. As long as these are not yet published,
// we still want to bake them from the WP posts. Once the users presses publish there though, we want to stop
// baking them from the wordpress post. Here we fetch all the slugs of posts that have been published via gdocs
// and exclude them from the baking process.
const alreadyPublishedViaGdocsSlugs = await db.knexRaw(`-- sql
select slug from posts_with_gdoc_publish_status
where isGdocPublished = TRUE`)
const alreadyPublishedViaGdocsSlugsSet = new Set(
alreadyPublishedViaGdocsSlugs.map((row: any) => row.slug)
)
const alreadyPublishedViaGdocsSlugsSet =
await db.getSlugsWithPublishedGdocsSuccessors()

const postsApi = await wpdb.getPosts(
undefined,
Expand Down
8 changes: 2 additions & 6 deletions baker/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,8 @@ const explorerToSitemapUrl = (program: ExplorerProgram): SitemapUrl[] => {
}

export const makeSitemap = async (explorerAdminServer: ExplorerAdminServer) => {
const alreadyPublishedViaGdocsSlugs = await db.knexRaw(`-- sql
select slug from posts_with_gdoc_publish_status
where isGdocPublished = TRUE`)
const alreadyPublishedViaGdocsSlugsSet = new Set(
alreadyPublishedViaGdocsSlugs.map((row: any) => row.slug)
)
const alreadyPublishedViaGdocsSlugsSet =
await db.getSlugsWithPublishedGdocsSuccessors()
const postsApi = await wpdb.getPosts(
undefined,
(postrow) => !alreadyPublishedViaGdocsSlugsSet.has(postrow.slug)
Expand Down
18 changes: 18 additions & 0 deletions db/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,21 @@ export const knexTable = (table: string): Knex.QueryBuilder =>
knexInstance().table(table)

export const knexRaw = (str: string): Knex.Raw => knexInstance().raw(str)

/**
* In the backporting workflow, the users create gdoc posts for posts. As long as these are not yet published,
* we still want to bake them from the WP posts. Once the users presses publish there though, we want to stop
* baking them from the wordpress post. This funciton fetches all the slugs of posts that have been published via gdocs,
* to help us exclude them from the baking process.
*/
export const getSlugsWithPublishedGdocsSuccessors = async (): Promise<
Set<string>
> => {
return knexRaw(
`-- sql
select slug from posts_with_gdoc_publish_status
where isGdocPublished = TRUE`
)
.then((res) => res[0])
.then((rows) => new Set(rows.map((row: any) => row.slug)))
}

0 comments on commit 9bf2c09

Please sign in to comment.