Skip to content

Commit 2c8902f

Browse files
committed
asyncify redirect loading
1 parent 7563adc commit 2c8902f

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

lib/redirects/precompile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ const developerRedirects = require('../redirects/static/developer')
22
const { latest } = require('../../lib/enterprise-server-releases')
33
const latestDevRedirects = {}
44

5-
// Replace hardcoded 'latest' with real value
5+
// Replace hardcoded 'latest' with real value in the redirected path
66
Object.entries(developerRedirects).forEach(([oldPath, newPath]) => {
77
latestDevRedirects[oldPath] = newPath.replace('enterprise-server@latest', `enterprise-server@${latest}`)
88
})
99

1010
// This function runs at server warmup and precompiles possible redirect routes.
1111
// It outputs them in key-value pairs within a neat Javascript object: { oldPath: newPath }
12-
module.exports = function precompileRedirects (pageList) {
12+
module.exports = async function precompileRedirects (pageList) {
1313
const allRedirects = Object.assign({}, latestDevRedirects)
1414

1515
// CURRENT PAGES PERMALINKS AND FRONTMATTER
1616
// create backwards-compatible old paths for page permalinks and frontmatter redirects
17-
pageList.forEach(page => Object.assign(allRedirects, page.buildRedirects()))
17+
await Promise.all(pageList.map(async(page) => Object.assign(allRedirects, page.buildRedirects())))
1818

1919
return allRedirects
2020
}

lib/warm-server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const loadSiteTree = require('./site-tree')
99
const dog = {
1010
loadPages: statsd.asyncTimer(loadPages, 'load_pages'),
1111
loadPageMap: statsd.asyncTimer(loadPageMap, 'load_page_map'),
12-
loadRedirects: statsd.timer(loadRedirects, 'load_redirects'),
12+
loadRedirects: statsd.asyncTimer(loadRedirects, 'load_redirects'),
1313
loadSiteData: statsd.timer(loadSiteData, 'load_site_data'),
1414
loadSiteTree: statsd.asyncTimer(loadSiteTree, 'load_site_tree')
1515
}
@@ -52,7 +52,7 @@ async function warmServer () {
5252
}
5353

5454
if (!redirects) {
55-
redirects = dog.loadRedirects(pageList, pageMap)
55+
redirects = await dog.loadRedirects(pageList, pageMap)
5656
}
5757

5858
if (!siteTree) {

0 commit comments

Comments
 (0)