Skip to content

Commit 1c2aa08

Browse files
janvennemannulivz
authored andcommitted
perf: improve ssr performance (#1068)
* 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
1 parent 550317e commit 1c2aa08

File tree

1 file changed

+10
-8
lines changed
  • packages/@vuepress/theme-default/util

1 file changed

+10
-8
lines changed

packages/@vuepress/theme-default/util/index.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,11 @@ export function resolvePage (pages, rawPath, base) {
5858
rawPath = resolvePath(rawPath, base)
5959
}
6060
const path = normalize(rawPath)
61-
for (let i = 0; i < pages.length; i++) {
62-
if (normalize(pages[i].regularPath) === path) {
63-
return Object.assign({}, pages[i], {
64-
type: 'page',
65-
path: ensureExt(pages[i].path)
66-
})
67-
}
61+
if (path in pages) {
62+
return Object.assign({}, pages[path], {
63+
type: 'page',
64+
path: ensureExt(pages[path].path)
65+
})
6866
}
6967
console.error(`[vuepress] No matching page found for sidebar item "${rawPath}"`)
7068
return {}
@@ -128,12 +126,16 @@ export function resolveSidebarItems (page, regularPath, site, localePath) {
128126
}
129127

130128
const sidebarConfig = localeConfig.sidebar || themeConfig.sidebar
129+
const normalizedPagesMap = pages.reduce((map, page) => {
130+
map[normalize(page.regularPath)] = page
131+
return map
132+
}, {})
131133
if (!sidebarConfig) {
132134
return []
133135
} else {
134136
const { base, config } = resolveMatchingConfig(regularPath, sidebarConfig)
135137
return config
136-
? config.map(item => resolveItem(item, pages, base))
138+
? config.map(item => resolveItem(item, normalizedPagesMap, base))
137139
: []
138140
}
139141
}

0 commit comments

Comments
 (0)