Skip to content

Commit

Permalink
perf: improve ssr performance (#1068)
Browse files Browse the repository at this point in the history
* perf: improve ssr performance and resolve memory leak

* reduce to normalized pages map

* assign and return map in reducer function

* return complete map from reduder function
  • Loading branch information
janvennemann authored and ulivz committed Dec 17, 2018
1 parent 550317e commit 1c2aa08
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/@vuepress/theme-default/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,11 @@ export function resolvePage (pages, rawPath, base) {
rawPath = resolvePath(rawPath, base)
}
const path = normalize(rawPath)
for (let i = 0; i < pages.length; i++) {
if (normalize(pages[i].regularPath) === path) {
return Object.assign({}, pages[i], {
type: 'page',
path: ensureExt(pages[i].path)
})
}
if (path in pages) {
return Object.assign({}, pages[path], {
type: 'page',
path: ensureExt(pages[path].path)
})
}
console.error(`[vuepress] No matching page found for sidebar item "${rawPath}"`)
return {}
Expand Down Expand Up @@ -128,12 +126,16 @@ export function resolveSidebarItems (page, regularPath, site, localePath) {
}

const sidebarConfig = localeConfig.sidebar || themeConfig.sidebar
const normalizedPagesMap = pages.reduce((map, page) => {
map[normalize(page.regularPath)] = page
return map
}, {})
if (!sidebarConfig) {
return []
} else {
const { base, config } = resolveMatchingConfig(regularPath, sidebarConfig)
return config
? config.map(item => resolveItem(item, pages, base))
? config.map(item => resolveItem(item, normalizedPagesMap, base))
: []
}
}
Expand Down

0 comments on commit 1c2aa08

Please sign in to comment.