Skip to content

Commit d66a088

Browse files
committed
we need to include the package name in this index, and also actually create the index
1 parent d70b276 commit d66a088

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

Sources/UnidocDB/Unidoc.DB.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ extension Unidoc.DB
600600

601601
try await self.redirects.insert(mesh.redirects)
602602
try await self.vertices.insert(mesh.vertices,
603-
latest: mesh.metadata.latest)
603+
trunk: mesh.metadata.latest ? mesh.metadata.symbol.package : nil)
604604
try await self.groups.insert(mesh.groups,
605605
realm: mesh.metadata.latest ? mesh.metadata.realm : nil)
606606

Sources/UnidocDB/Vertices/Unidoc.DB.Vertices.VacuumLatest.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ extension Unidoc.DB.Vertices.VacuumLatest:Mongo.UpdateQuery
5151
$0[.u]
5252
{
5353
$0[.unset] { $0[Unidoc.AnyVertex[.linkable]] = true }
54+
$0[.unset] { $0[Unidoc.AnyVertex[.trunk]] = true }
5455
}
5556
}
5657
}

Sources/UnidocDB/Vertices/Unidoc.DB.Vertices.swift

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import MongoDB
22
import MongoQL
3+
import Symbols
34
import Unidoc
45
import UnidocRecords
56

@@ -62,9 +63,10 @@ extension Unidoc.DB.Vertices
6263
}
6364

6465
public
65-
static let indexLinkableStem:Mongo.CollectionIndex = .init("LinkableStem",
66+
static let indexLinkablePath:Mongo.CollectionIndex = .init("LinkablePath",
6667
collation: .casefolding)
6768
{
69+
$0[Unidoc.AnyVertex[.trunk]] = (+)
6870
$0[Unidoc.AnyVertex[.stem]] = (+)
6971
}
7072
where:
@@ -81,7 +83,15 @@ extension Unidoc.DB.Vertices:Mongo.CollectionModel
8183
var name:Mongo.Collection { "VolumeVertices" }
8284

8385
@inlinable public static
84-
var indexes:[Mongo.CollectionIndex] { [ Self.indexStem, Self.indexHash ] }
86+
var indexes:[Mongo.CollectionIndex]
87+
{
88+
[
89+
Self.indexStem,
90+
Self.indexHash,
91+
Self.indexLinkableFlag,
92+
Self.indexLinkablePath,
93+
]
94+
}
8595
}
8696
@available(*, unavailable, message: """
8797
Vertices contain flags set by the database, which would be lost if they were decoded and \
@@ -93,7 +103,8 @@ extension Unidoc.DB.Vertices:Mongo.RecodableModel
93103
extension Unidoc.DB.Vertices
94104
{
95105
@discardableResult
96-
func insert(_ vertices:Unidoc.Mesh.Vertices, latest:Bool) async throws -> Mongo.Insertions
106+
func insert(_ vertices:Unidoc.Mesh.Vertices,
107+
trunk:Symbol.Package?) async throws -> Mongo.Insertions
97108
{
98109
let response:Mongo.InsertResponse = try await session.run(
99110
command: Mongo.Insert.init(Self.name,
@@ -109,7 +120,11 @@ extension Unidoc.DB.Vertices
109120
{
110121
Unidoc.AnyVertex.article(article).encode(to: &$0)
111122

112-
$0[.linkable] = latest ? latest : nil
123+
if let trunk:Symbol.Package
124+
{
125+
$0[.linkable] = true
126+
$0[.trunk] = trunk
127+
}
113128
}
114129
}
115130

Sources/UnidocRecords/Volumes/Vertices/Unidoc.AnyVertex.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ extension Unidoc.AnyVertex
169169
case extendee = "j"
170170
/// Appears in ``ArticleVertex``, ``DeclVertex``, ``CultureVertex``, and ``FileVertex``.
171171
case symbol = "Y"
172+
173+
/// Appears in ``ArticleVertex`` only, used for direct linking. This should only appear
174+
/// if ``linkable`` is true.
175+
case trunk = "V"
172176
/// Appears in every vertex type except for ``FileVertex``. In ``LandingVertex``, it is
173177
/// always the empty string.
174178
case stem = "U"

0 commit comments

Comments
 (0)