зеркало из https://github.com/github/docs.git
asyncify redirect loading
This commit is contained in:
Родитель
7563adce8a
Коммит
2c8902f826
|
@ -2,19 +2,19 @@ const developerRedirects = require('../redirects/static/developer')
|
|||
const { latest } = require('../../lib/enterprise-server-releases')
|
||||
const latestDevRedirects = {}
|
||||
|
||||
// Replace hardcoded 'latest' with real value
|
||||
// Replace hardcoded 'latest' with real value in the redirected path
|
||||
Object.entries(developerRedirects).forEach(([oldPath, newPath]) => {
|
||||
latestDevRedirects[oldPath] = newPath.replace('enterprise-server@latest', `enterprise-server@${latest}`)
|
||||
})
|
||||
|
||||
// This function runs at server warmup and precompiles possible redirect routes.
|
||||
// It outputs them in key-value pairs within a neat Javascript object: { oldPath: newPath }
|
||||
module.exports = function precompileRedirects (pageList) {
|
||||
module.exports = async function precompileRedirects (pageList) {
|
||||
const allRedirects = Object.assign({}, latestDevRedirects)
|
||||
|
||||
// CURRENT PAGES PERMALINKS AND FRONTMATTER
|
||||
// create backwards-compatible old paths for page permalinks and frontmatter redirects
|
||||
pageList.forEach(page => Object.assign(allRedirects, page.buildRedirects()))
|
||||
await Promise.all(pageList.map(async(page) => Object.assign(allRedirects, page.buildRedirects())))
|
||||
|
||||
return allRedirects
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ const loadSiteTree = require('./site-tree')
|
|||
const dog = {
|
||||
loadPages: statsd.asyncTimer(loadPages, 'load_pages'),
|
||||
loadPageMap: statsd.asyncTimer(loadPageMap, 'load_page_map'),
|
||||
loadRedirects: statsd.timer(loadRedirects, 'load_redirects'),
|
||||
loadRedirects: statsd.asyncTimer(loadRedirects, 'load_redirects'),
|
||||
loadSiteData: statsd.timer(loadSiteData, 'load_site_data'),
|
||||
loadSiteTree: statsd.asyncTimer(loadSiteTree, 'load_site_tree')
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ async function warmServer () {
|
|||
}
|
||||
|
||||
if (!redirects) {
|
||||
redirects = dog.loadRedirects(pageList, pageMap)
|
||||
redirects = await dog.loadRedirects(pageList, pageMap)
|
||||
}
|
||||
|
||||
if (!siteTree) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче