Skip to content

Commit

Permalink
🐝 remove explorer redirect resolution in gdoc validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed Oct 8, 2024
1 parent ac5579c commit 6d314b4
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 29 deletions.
7 changes: 1 addition & 6 deletions db/model/Gdoc/GdocBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import {
OwidGdocContent,
OwidGdocType,
} from "@ourworldindata/types"
import { getRedirectsFromDb, resolveRedirects } from "../Redirect.js"

export class GdocBase implements OwidGdocBaseInterface {
id!: string
Expand Down Expand Up @@ -751,8 +750,6 @@ export class GdocBase implements OwidGdocBaseInterface {
const chartIdsBySlug = await mapSlugsToIds(knex)
const publishedExplorersBySlug =
await db.getPublishedExplorersBySlug(knex)
const redirects = await getRedirectsFromDb(knex)
const resolvedRedirects = resolveRedirects(redirects)

const linkErrors: OwidGdocErrorMessage[] = this.links.reduce(
(errors: OwidGdocErrorMessage[], link): OwidGdocErrorMessage[] => {
Expand Down Expand Up @@ -783,9 +780,7 @@ export class GdocBase implements OwidGdocBaseInterface {
}

if (link.linkType === "explorer") {
const resolvedTarget =
resolvedRedirects.get(link.target) ?? link.target
if (!publishedExplorersBySlug[resolvedTarget]) {
if (!publishedExplorersBySlug[link.target]) {
errors.push({
property: "content",
message: `Explorer chart with slug ${link.target} does not exist or is not published`,
Expand Down
23 changes: 0 additions & 23 deletions db/model/Redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,6 @@ export async function getRedirects(
)
}

/**
* Takes a list of redirects and returns a map of source -> target
* such that if you have [A -> B, B -> C], the map will be { A -> C, B -> C }
*/
export function resolveRedirects(
redirects: Pick<DbPlainRedirect, "source" | "target">[]
): Map<string, string> {
const asMap = new Map<string, string>(
redirects.map(({ source, target }) => [source, target])
)
const resolved = new Map<string, string>()

for (const [source, target] of asMap) {
let current = target
while (asMap.has(current)) {
current = asMap.get(current)!
}
resolved.set(source, current)
}

return resolved
}

export async function getRedirectById(
knex: db.KnexReadonlyTransaction,
id: number
Expand Down

0 comments on commit 6d314b4

Please sign in to comment.