-
Notifications
You must be signed in to change notification settings - Fork 60
Fix loading performance for pages with many links caused by excessive re-computation #900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mportiz08
merged 9 commits into
swiftlang:main
from
mportiz08:avoid-recomputing-refs-in-mixin
Oct 9, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2797dcf
Re-calc inactive refs when assigning them to global store.
mportiz08 19e9d70
Fix existing specs.
mportiz08 4ef2904
Add specs for `filterInactiveReferences`.
mportiz08 50bf72c
Update store specs.
mportiz08 58bcb03
Test watchers that update refs.
mportiz08 249eabe
Add specs for `[store].updateReferences`.
mportiz08 e80bca7
Remove update logic from components where index data is not fetched.
mportiz08 f253310
Remove unecessary filtering from non-doc page store logic.
mportiz08 7e0e22f
Merge branch 'main' into avoid-recomputing-refs-in-mixin
mportiz08 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* This source file is part of the Swift.org open source project | ||
* | ||
* Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
* Licensed under Apache License v2.0 with Runtime Library Exception | ||
* | ||
* See https://swift.org/LICENSE.txt for license information | ||
* See https://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
*/ | ||
|
||
import AppStore from 'docc-render/stores/AppStore'; | ||
|
||
const TopicReferenceTypes = new Set([ | ||
'section', | ||
'topic', | ||
]); | ||
|
||
function isFromIncludedArchive(id) { | ||
const { includedArchiveIdentifiers } = AppStore.state; | ||
|
||
// for backwards compatibility purposes, treat all references as being | ||
// from included archives if there is no data for it | ||
if (!includedArchiveIdentifiers.length) { | ||
return true; | ||
} | ||
|
||
return includedArchiveIdentifiers.some(archiveId => ( | ||
id?.startsWith(`doc://${archiveId}/`) | ||
)); | ||
} | ||
|
||
function filterInactiveReferences(references = {}) { | ||
return Object.keys(references).reduce((newRefs, id) => { | ||
const originalRef = references[id]; | ||
const { url, ...refWithoutUrl } = originalRef; | ||
return TopicReferenceTypes.has(originalRef.type) ? ({ | ||
...newRefs, | ||
[id]: isFromIncludedArchive(id) ? originalRef : refWithoutUrl, | ||
}) : ({ | ||
...newRefs, | ||
[id]: originalRef, | ||
}); | ||
}, {}); | ||
} | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export { filterInactiveReferences }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* This source file is part of the Swift.org open source project | ||
* | ||
* Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
* Licensed under Apache License v2.0 with Runtime Library Exception | ||
* | ||
* See https://swift.org/LICENSE.txt for license information | ||
* See https://swift.org/CONTRIBUTORS.txt for Swift project authors | ||
*/ | ||
|
||
import AppStore from 'docc-render/stores/AppStore'; | ||
import { filterInactiveReferences } from 'docc-render/utils/references'; | ||
|
||
const aa = { | ||
identifier: 'doc://A/documentation/A/a', | ||
url: '/documentation/A/a', | ||
title: 'A.A', | ||
type: 'topic', | ||
}; | ||
const ab = { | ||
identifier: 'doc://A/documentation/A/b', | ||
url: '/documentation/A/b', | ||
title: 'A.B', | ||
type: 'topic', | ||
}; | ||
const bb = { | ||
identifier: 'doc://B/documentation/B/b', | ||
url: '/documentation/B/b', | ||
title: 'B.B', | ||
type: 'topic', | ||
}; | ||
const bbb = { | ||
identifier: 'doc://BB/documentation/BB/b', | ||
url: '/documentation/BB/b#b', | ||
title: 'BB.B', | ||
type: 'section', | ||
}; | ||
const c = { | ||
identifier: 'https://abc.dev', | ||
url: 'https://abc.dev', | ||
title: 'C', | ||
type: 'link', | ||
}; | ||
|
||
const references = { | ||
[aa.identifier]: aa, | ||
[ab.identifier]: ab, | ||
[bb.identifier]: bb, | ||
[bbb.identifier]: bbb, | ||
[c.identifier]: c, | ||
}; | ||
|
||
describe('filterInactiveReferences', () => { | ||
it('does not filter any refs when `includedArchiveIdentifiers` is empty', () => { | ||
AppStore.setIncludedArchiveIdentifiers([]); | ||
expect(filterInactiveReferences(references)).toEqual(references); | ||
}); | ||
|
||
it('does not filter any refs when `includedArchiveIdentifiers` includes all ref archives', () => { | ||
AppStore.setIncludedArchiveIdentifiers(['A', 'B', 'BB']); | ||
expect(filterInactiveReferences(references)).toEqual(references); | ||
}); | ||
|
||
it('removes `url` from non-external refs that aren\'t part of included archive', () => { | ||
AppStore.setIncludedArchiveIdentifiers(['B']); | ||
const filteredRefs = filterInactiveReferences(references); | ||
|
||
expect(Object.keys(filteredRefs)).toEqual(Object.keys(references)); | ||
|
||
expect(filteredRefs[aa.identifier].url).toBeFalsy(); | ||
expect(filteredRefs[ab.identifier].url).toBeFalsy(); | ||
expect(filteredRefs[bb.identifier].url).toBe(bb.url); | ||
expect(filteredRefs[bbb.identifier].url).toBeFalsy(); | ||
expect(filteredRefs[c.identifier].url).toBe(c.url); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.