Skip to content

Commit 5694c1f

Browse files
committed
Make rootModules a stored property
Makes DocumentationContext.rootModules a stored property instead of a computed property for performance reasons.
1 parent c1ce32f commit 5694c1f

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

Sources/SwiftDocC/Infrastructure/DocumentationContext.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,9 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
138138
}
139139

140140
/// The root module nodes of the Topic Graph.
141-
public var rootModules: [ResolvedTopicReference] {
142-
return topicGraph.nodes.values.compactMap { node in
143-
guard node.kind == .module,
144-
!onlyHasSnippetRelatedChildren(for: node.reference) else {
145-
return nil
146-
}
147-
return node.reference
148-
}
149-
}
141+
///
142+
/// This property is initialized during the registration of a documentation bundle.
143+
public private(set) var rootModules: [ResolvedTopicReference]!
150144

151145
/// The topic reference of the root module, if it's the only registered module.
152146
var soleRootModuleReference: ResolvedTopicReference? {
@@ -1859,6 +1853,16 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
18591853

18601854
try shouldContinueRegistration()
18611855

1856+
// Keep track of the root modules registered from symbol graph files, we'll need them to automatically
1857+
// curate articles.
1858+
rootModules = topicGraph.nodes.values.compactMap { node in
1859+
guard node.kind == .module,
1860+
!onlyHasSnippetRelatedChildren(for: node.reference) else {
1861+
return nil
1862+
}
1863+
return node.reference
1864+
}
1865+
18621866
// Articles that will be automatically curated can be resolved but they need to be pre registered before resolving links.
18631867
let rootNodeForAutomaticCuration = soleRootModuleReference.flatMap(topicGraph.nodeWithReference(_:))
18641868
if rootNodeForAutomaticCuration != nil {

0 commit comments

Comments
 (0)