From 8a375ce9e0a7f8e13b811431ef31cbfc209d3e11 Mon Sep 17 00:00:00 2001 From: Matthieu Bergel Date: Fri, 9 Feb 2024 13:41:24 +0000 Subject: [PATCH] refactor: resolve internal redirects from db --- baker/redirects.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/baker/redirects.ts b/baker/redirects.ts index 11550a837ab..b2a8db2b30f 100644 --- a/baker/redirects.ts +++ b/baker/redirects.ts @@ -1,5 +1,4 @@ import * as db from "../db/db.js" -import * as wpdb from "../db/wpdb.js" import { memoize, JsonError, Url } from "@ourworldindata/utils" import { isCanonicalInternalUrl } from "./formatting.js" import { resolveExplorerRedirect } from "./replaceExplorerRedirects.js" @@ -101,14 +100,12 @@ const stripTrailingSlash = (url: string) => { } export const getWordpressRedirectsMap = async () => { - const wordpressRedirectRows = (await wpdb.singleton.query( - `SELECT url, action_data FROM wp_redirection_items WHERE status = 'enabled'` - )) as Array<{ url: string; action_data: string }> + const redirectsFromDb = await getRedirectsFromDb() return new Map( - wordpressRedirectRows.map((row) => [ - stripTrailingSlash(row.url), - stripTrailingSlash(row.action_data), + redirectsFromDb.map((row) => [ + stripTrailingSlash(row.source), + stripTrailingSlash(row.target), ]) ) }