Skip to content

Commit

Permalink
🔨 change code to sync reusable blocks into the grapher db posts table
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Dec 1, 2023
1 parent 52cd668 commit af8fc54
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions adminSiteServer/apiRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2273,6 +2273,7 @@ apiRouter.get("/posts.json", async (req) => {
db
.knexInstance()
.from(postsTable)
.whereNotIn("type", ["wp_block"])
.orderBy("updated_at_in_wordpress", "desc")
)

Expand Down
3 changes: 2 additions & 1 deletion baker/SiteBaker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class SiteBaker {
if (!this.bakeSteps.has("embeds")) return
// Find all grapher urls used as embeds in all posts on the site
const rows = await wpdb.singleton.query(
`SELECT post_content FROM wp_posts WHERE (post_type='page' OR post_type='post' OR post_type='wp_block') AND post_status='publish'`
`SELECT post_content FROM wp_posts WHERE (post_type='page' OR post_type='post') AND post_status='publish'`
)
let grapherUrls = []
for (const row of rows) {
Expand Down Expand Up @@ -553,6 +553,7 @@ export class SiteBaker {
const rows = (await db
.knexTable(postsTable)
.where({ status: "publish" })
.whereNotIn("type", ["wp_block"])
.join("post_tags", { "post_tags.post_id": "posts.id" })
.join("tags", { "tags.id": "post_tags.tag_id" })
.where({ "tags.name": "Entries" })
Expand Down
1 change: 1 addition & 0 deletions baker/siteRenderers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ ${posts
export const entriesByYearPage = async (year?: number) => {
const entries = (await knexTable(postsTable)
.where({ status: "publish" })
.whereNotIn("type", ["wp_block"])
.join("post_tags", { "post_tags.post_id": "posts.id" })
.join("tags", { "tags.id": "post_tags.tag_id" })
.where({ "tags.name": "Entries" })
Expand Down
2 changes: 1 addition & 1 deletion db/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const getSlugsWithPublishedGdocsSuccessors = async (): Promise<
return knexRaw(
`-- sql
select slug from posts_with_gdoc_publish_status
where isGdocPublished = TRUE`
where isGdocPublished = TRUE and type <> 'wp_block'`
)
.then((res) => res[0])
.then((rows) => new Set(rows.map((row: any) => row.slug)))
Expand Down
4 changes: 2 additions & 2 deletions db/syncPostsToGrapher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function buildReplacerFunction(
) => {
const block = blocks[matches["id"].toString()]
return block
? `<!-- wp-block-tombstone ${matches["id"]} -->` +
? `<!-- wp-block-tombstone ${matches["id"]} -->\n` +
block.post_content
: ""
}
Expand Down Expand Up @@ -262,7 +262,7 @@ const syncPostsToGrapher = async (): Promise<void> => {
left join post_ids_with_authors pwa on p.ID = pwa.ID
left join first_revision fr on fr.post_id = pwa.ID
left join post_featured_image fi on fi.ID = p.id
where p.post_type in ('post', 'page') AND post_status != 'trash'
where p.post_type in ('post', 'page', 'wp_block') AND post_status != 'trash'
`
)

Expand Down
1 change: 1 addition & 0 deletions db/wpdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ export const getRelatedResearchAndWritingForVariable = async (
-- be disregarded
and componentType = 'src'
and cd.variableId = ?
and p.type <> 'wp_block'
and cd.property in ('x', 'y') -- ignore cases where the indicator is size, color etc
and p.status = 'publish' -- only use published wp posts
and coalesce(pg.published, 0) = 0 -- ignore posts if the wp post has a published gdoc successor. The
Expand Down

0 comments on commit af8fc54

Please sign in to comment.