Skip to content

Commit

Permalink
🎉 include non-grapher explorer views in homepage chart count
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed Apr 16, 2024
1 parent 681fab1 commit fe0fb50
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
24 changes: 24 additions & 0 deletions db/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,27 @@ export const getHomepageId = (
AND published = TRUE`
).then((result) => result?.id)
}

export const getNonGrapherExplorerViewCount = (
knex: KnexReadonlyTransaction
): Promise<number> => {
return knexRawFirst<{ count: number }>(
knex,
`-- sql
SELECT
COUNT(*) as count
FROM
explorers,
json_table(config, "$.blocks[*]"
COLUMNS (
type TEXT PATH "$.type",
NESTED PATH "$.block[*]"
COLUMNS (grapherId INT PATH "$.grapherId")
)
) t1
WHERE
isPublished = 1
AND type = "graphers"
AND grapherId IS NULL`
).then((res) => res?.count ?? 0)
}
6 changes: 5 additions & 1 deletion db/model/Gdoc/GdocHomepage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ export class GdocHomepage
_loadSubclassAttachments = async (
knex: db.KnexReadonlyTransaction
): Promise<void> => {
const grapherCount = await db.getTotalNumberOfCharts(knex)
const nonGrapherExplorerViewCount =
await db.getNonGrapherExplorerViewCount(knex)

this.homepageMetadata = {
chartCount: await db.getTotalNumberOfCharts(knex),
chartCount: grapherCount + nonGrapherExplorerViewCount,
topicCount: UNIQUE_TOPIC_COUNT,
}

Expand Down

0 comments on commit fe0fb50

Please sign in to comment.