Skip to content

Commit

Permalink
refactor(db): use computed gdocs type column
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber committed Apr 25, 2024
1 parent c42927f commit f9f3bdd
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions db/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export const getPublishedGdocPosts = async (
posts_gdocs g
WHERE
g.published = 1
AND g.content ->> '$.type' IN (:types)
AND g.type IN (:types)
AND g.publishedAt <= NOW()
ORDER BY g.publishedAt DESC`,
{
Expand Down Expand Up @@ -410,7 +410,7 @@ export const getPublishedGdocPostsWithTags = async (
gxt.tagId = t.id
WHERE
g.published = 1
AND g.content ->> '$.type' IN (:types)
AND g.type IN (:types)
AND g.publishedAt <= NOW()
GROUP BY g.id
ORDER BY g.publishedAt DESC`,
Expand Down
2 changes: 1 addition & 1 deletion db/model/Gdoc/GdocBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ export async function getMinimalGdocPostsByIds(
published,
content ->> '$.subtitle' as subtitle,
content ->> '$.excerpt' as excerpt,
content ->> '$.type' as type,
type,
content ->> '$."featured-image"' as "featured-image"
FROM posts_gdocs
WHERE id in (:ids)`,
Expand Down
6 changes: 3 additions & 3 deletions db/model/Gdoc/GdocFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export async function getAllMinimalGdocBaseObjects(
published,
content ->> '$.subtitle' as subtitle,
content ->> '$.excerpt' as excerpt,
content ->> '$.type' as type,
type,
content ->> '$."featured-image"' as "featured-image"
FROM posts_gdocs
WHERE published = 1
Expand Down Expand Up @@ -363,7 +363,7 @@ export async function getAndLoadPublishedDataInsights(
SELECT *
FROM posts_gdocs
WHERE published = 1
AND content ->> '$.type' = ?
AND type = ?
AND publishedAt <= NOW()
ORDER BY publishedAt DESC
${limitOffsetClause}`,
Expand Down Expand Up @@ -413,7 +413,7 @@ export async function loadPublishedGdocAuthors(
SELECT *
FROM posts_gdocs
WHERE published = 1
AND content ->> '$.type' IN (:types)`,
AND type IN (:types)`,
{
types: [OwidGdocType.Author],
}
Expand Down
2 changes: 1 addition & 1 deletion db/model/Gdoc/GdocHomepage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class GdocHomepage
SELECT
id
FROM posts_gdocs
WHERE content->>"$.type" = "${OwidGdocType.Homepage}"
WHERE type = "${OwidGdocType.Homepage}"
AND published = TRUE
AND id != ?`,
[this.id]
Expand Down
4 changes: 2 additions & 2 deletions db/model/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ export const getWordpressPostReferencesByChartId = async (
slug from posts_gdocs pg
WHERE
pg.slug = p.slug
AND pg.content ->> '$.type' <> 'fragment'
AND pg.type != 'fragment'
AND pg.published = 1
)
ORDER BY
Expand Down Expand Up @@ -563,7 +563,7 @@ export const getRelatedResearchAndWritingForVariable = async (
AND cd.variableId = ?
AND cd.property IN ('x', 'y') -- ignore cases where the indicator is size, color etc
AND p.published = 1
AND p.content ->> '$.type' != 'fragment'`,
AND p.type != 'fragment'`,
[variableId]
)

Expand Down

0 comments on commit f9f3bdd

Please sign in to comment.