From a557b80460760467c7974ee0b4216fa48b2aecc3 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 18 Oct 2022 22:55:58 +0200 Subject: [PATCH 1/2] Speed up /categories.json (#31831) --- middleware/categories-for-support.js | 41 ++++++++++++---------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/middleware/categories-for-support.js b/middleware/categories-for-support.js index 4094a5d289..72ca2fef66 100644 --- a/middleware/categories-for-support.js +++ b/middleware/categories-for-support.js @@ -10,34 +10,27 @@ const cacheControl = cacheControlFactory(60 * 60 * 24) // GitHub Support uses this for internal ZenDesk search functionality. export default async function categoriesForSupport(req, res) { const englishSiteTree = req.context.siteTree.en - const allCategories = [] - await Promise.all( - Object.keys(englishSiteTree).map(async (version) => { - await Promise.all( - englishSiteTree[version].childPages.map(async (productPage) => { - if (productPage.page.relativePath.startsWith('early-access')) return - if (!productPage.childPages) return - await Promise.all( - productPage.childPages.map(async (categoryPage) => { - // We can't get the rendered titles from middleware/render-tree-titles - // here because that middleware only runs on the current version, and this - // middleware processes all versions. - const name = categoryPage.page.title.includes('{') - ? await categoryPage.page.renderProp('title', req.context, renderOpts) - : categoryPage.page.title + for (const productPage of Object.values(englishSiteTree['free-pro-team@latest'].childPages)) { + if (productPage.page.relativePath.startsWith('early-access')) continue + if (!productPage.childPages || !productPage.childPages.length) continue + await Promise.all( + productPage.childPages.map(async (categoryPage) => { + // We can't get the rendered titles from middleware/render-tree-titles + // here because that middleware only runs on the current version, and this + // middleware processes all versions. + const name = categoryPage.page.title.includes('{') + ? await categoryPage.page.renderProp('title', req.context, renderOpts) + : categoryPage.page.title - allCategories.push({ - name, - published_articles: await findArticlesPerCategory(categoryPage, [], req.context), - }) - }) - ) + allCategories.push({ + name, + published_articles: await findArticlesPerCategory(categoryPage, [], req.context), }) - ) - }) - ) + }) + ) + } // Cache somewhat aggressively but note that it will be soft-purged // in every prod deployment. From 7fe89141b3f60019826e4aede87dfc4e2b8cae5b Mon Sep 17 00:00:00 2001 From: Hector Alfaro Date: Tue, 18 Oct 2022 16:59:56 -0400 Subject: [PATCH 2/2] Remove translation directory dependency from `convert-if-to-ifversion.js` (#31835) --- script/content-migrations/convert-if-to-ifversion.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/script/content-migrations/convert-if-to-ifversion.js b/script/content-migrations/convert-if-to-ifversion.js index a821cd056d..c71b45d59d 100755 --- a/script/content-migrations/convert-if-to-ifversion.js +++ b/script/content-migrations/convert-if-to-ifversion.js @@ -12,8 +12,6 @@ import walkFiles from '../helpers/walk-files.js' const allFiles = walkFiles('content', '.md') .concat(walkFiles('data', ['.yml', '.md'])) - // We need to update translations files directly so the new tests don't fail on them. - .concat(walkFiles('translations', ['.yml', '.md'])) // GraphQL content files have some non-FBV if statements that we don't want to change. // Fortunately they do not include any FBV if statements, so we can just ignore the whole dir. .filter((file) => !file.includes('/content/graphql/'))