Skip to content

Commit

Permalink
speeds O(n^2) execution of detectConflictingPaths (#46080)
Browse files Browse the repository at this point in the history
## Bug

- [x] Related issues linked using `fixes #46079` #46079
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
  • Loading branch information
0xadada authored Feb 20, 2023
1 parent d7b479a commit ce46922
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/next/src/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,17 @@ export function detectConflictingPaths(
>()

const dynamicSsgPages = [...ssgPages].filter((page) => isDynamicRoute(page))
const additionalSsgPathsByPath: {
[page: string]: { [path: string]: string }
} = {}

additionalSsgPaths.forEach((paths, pathsPage) => {
additionalSsgPathsByPath[pathsPage] ||= {}
paths.forEach((curPath) => {
const currentPath = curPath.toLowerCase()
additionalSsgPathsByPath[pathsPage][currentPath] = curPath
})
})

additionalSsgPaths.forEach((paths, pathsPage) => {
paths.forEach((curPath) => {
Expand All @@ -1573,9 +1584,10 @@ export function detectConflictingPaths(
conflictingPage = dynamicSsgPages.find((page) => {
if (page === pathsPage) return false

conflictingPath = additionalSsgPaths
.get(page)
?.find((compPath) => compPath.toLowerCase() === lowerPath)
conflictingPath =
additionalSsgPaths.get(page) == null
? undefined
: additionalSsgPathsByPath[page][lowerPath]
return conflictingPath
})

Expand Down

0 comments on commit ce46922

Please sign in to comment.