From 9bf2c09cbc745d07a881e16a2a47be6df2d9a30d Mon Sep 17 00:00:00 2001 From: Ike Saunders Date: Thu, 26 Oct 2023 15:47:01 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20baking-with-gdocs-successo?= =?UTF-8?q?r=20filtering=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- baker/SiteBaker.tsx | 12 ++---------- baker/sitemap.ts | 8 ++------ db/db.ts | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/baker/SiteBaker.tsx b/baker/SiteBaker.tsx index 9fb72acd358..5dcf3c4bd64 100644 --- a/baker/SiteBaker.tsx +++ b/baker/SiteBaker.tsx @@ -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, diff --git a/baker/sitemap.ts b/baker/sitemap.ts index 2a285fe06fe..578cc7095b1 100644 --- a/baker/sitemap.ts +++ b/baker/sitemap.ts @@ -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) diff --git a/db/db.ts b/db/db.ts index a301bb2fc58..fb04c286fdd 100644 --- a/db/db.ts +++ b/db/db.ts @@ -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 +> => { + 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))) +}