Skip to content

Commit 3cfb916

Browse files
committed
fix bug causing extraneous foreign vertices to be generated, and fix a different bug preventing group layer filtering from working properly
1 parent 230232a commit 3cfb916

File tree

8 files changed

+138
-74
lines changed

8 files changed

+138
-74
lines changed

Sources/SwiftinitServer/Endpoints/Procedural/Swiftinit.GlobalUplinkEndpoint.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ extension Swiftinit.GlobalUplinkEndpoint:NonblockingEndpoint
2525
session:Mongo.Session,
2626
status:Status) async
2727
{
28-
try? await server.db.unidoc.rebuildVolumes(queue: self.queue, with: session)
28+
do
29+
{
30+
try await server.db.unidoc.rebuildVolumes(queue: self.queue, with: session)
31+
}
32+
catch let error
33+
{
34+
print("global uplink failed: \(error)")
35+
}
2936
}
3037
}

Sources/UnidocAPI/Unidoc.Stem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Symbols
22

33
extension Unidoc
44
{
5-
/// A stem is a special representation of a master record’s lexical name within a snapshot.
5+
/// A stem is a special representation of a vertex’s lexical name within a snapshot.
66
/// A stem always begins with a ``Symbol.Module``.
77
///
88
/// ## Empty stems

Sources/UnidocLinker/Curation/Unidoc.Linker.TreeMapper.swift

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,27 @@ extension Unidoc.Linker.TreeMapper
6666
with context:borrowing Unidoc.Linker,
6767
as index:Int) -> Unidoc.ForeignVertex?
6868
{
69+
if case nil = self.local[foreign]
6970
{
70-
if case nil = $0
7171
{
72-
let vertex:Unidoc.ForeignVertex = Self.create(foreign: foreign,
73-
with: context,
74-
as: index)
75-
$0 = (vertex.shoot, vertex.flags)
76-
return vertex
77-
}
78-
else
79-
{
80-
return nil
81-
}
82-
} (&self.foreign[foreign])
72+
if case nil = $0
73+
{
74+
let vertex:Unidoc.ForeignVertex = Self.create(foreign: foreign,
75+
with: context,
76+
as: index)
77+
$0 = (vertex.shoot, vertex.flags)
78+
return vertex
79+
}
80+
else
81+
{
82+
return nil
83+
}
84+
} (&self.foreign[foreign])
85+
}
86+
else
87+
{
88+
nil
89+
}
8390
}
8491

8592
private static

Sources/UnidocQueries/Volumes/Unidoc.LookupAdjacent.LatestExtensions.swift

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ extension Unidoc.LookupAdjacent
77
{
88
struct LatestExtensions
99
{
10-
let layer:Unidoc.GroupLayerPredicate
10+
let layer:Unidoc.GroupLayer?
1111
let scope:Mongo.Variable<Unidoc.Scalar>
1212
let id:Mongo.Variable<Unidoc.Realm>
1313

1414
init(
15-
layer:Unidoc.GroupLayerPredicate,
15+
layer:Unidoc.GroupLayer?,
1616
scope:Mongo.Variable<Unidoc.Scalar>,
1717
id:Mongo.Variable<Unidoc.Realm>)
1818
{
@@ -25,23 +25,41 @@ extension Unidoc.LookupAdjacent
2525
extension Unidoc.LookupAdjacent.LatestExtensions
2626
{
2727
static
28-
func += (list:inout BSON.ListEncoder, self:Self)
28+
func += (or:inout Mongo.PredicateListEncoder, self:Self)
2929
{
30-
list.expr
30+
or.append
3131
{
3232
$0[.and] = .init
3333
{
34-
$0.expr
34+
$0.append
3535
{
36-
$0[.eq] = (Unidoc.AnyGroup[.layer], self.layer)
36+
// Alas, it is not as simple as performing an `$eq` match on `null`.
37+
guard
38+
let layer:Unidoc.GroupLayer = self.layer
39+
else
40+
{
41+
$0[Unidoc.AnyGroup[.layer]] = .init { $0[.exists] = false }
42+
return
43+
}
44+
45+
$0[.expr] = .expr
46+
{
47+
$0[.eq] = (Unidoc.AnyGroup[.layer], layer)
48+
}
3749
}
38-
$0.expr
50+
$0.append
3951
{
40-
$0[.eq] = (Unidoc.AnyGroup[.scope], self.scope)
52+
$0[.expr] = .expr
53+
{
54+
$0[.eq] = (Unidoc.AnyGroup[.scope], self.scope)
55+
}
4156
}
42-
$0.expr
57+
$0.append
4358
{
44-
$0[.eq] = (Unidoc.AnyGroup[.realm], self.id)
59+
$0[.expr] = .expr
60+
{
61+
$0[.eq] = (Unidoc.AnyGroup[.realm], self.id)
62+
}
4563
}
4664
}
4765
}

Sources/UnidocQueries/Volumes/Unidoc.LookupAdjacent.LockedExtensions.swift

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ extension Unidoc.LookupAdjacent
77
{
88
struct LockedExtensions
99
{
10-
let layer:Unidoc.GroupLayerPredicate
10+
let layer:Unidoc.GroupLayer?
1111
let scope:Mongo.Variable<Unidoc.Scalar>
1212
let min:Mongo.Variable<BSON.Identifier>
1313
let max:Mongo.Variable<BSON.Identifier>
1414

1515
init(
16-
layer:Unidoc.GroupLayerPredicate,
16+
layer:Unidoc.GroupLayer?,
1717
scope:Mongo.Variable<Unidoc.Scalar>,
1818
min:Mongo.Variable<BSON.Identifier>,
1919
max:Mongo.Variable<BSON.Identifier>)
@@ -28,27 +28,47 @@ extension Unidoc.LookupAdjacent
2828
extension Unidoc.LookupAdjacent.LockedExtensions
2929
{
3030
static
31-
func += (list:inout BSON.ListEncoder, self:Self)
31+
func += (or:inout Mongo.PredicateListEncoder, self:Self)
3232
{
33-
list.expr
33+
or.append
3434
{
3535
$0[.and] = .init
3636
{
37-
$0.expr
37+
$0.append
3838
{
39-
$0[.eq] = (Unidoc.AnyGroup[.layer], self.layer)
39+
guard
40+
let layer:Unidoc.GroupLayer = self.layer
41+
else
42+
{
43+
$0[Unidoc.AnyGroup[.layer]] = .init { $0[.exists] = false }
44+
return
45+
}
46+
47+
$0[.expr] = .expr
48+
{
49+
$0[.eq] = (Unidoc.AnyGroup[.layer], layer)
50+
}
4051
}
41-
$0.expr
52+
$0.append
4253
{
43-
$0[.eq] = (Unidoc.AnyGroup[.scope], self.scope)
54+
$0[.expr] = .expr
55+
{
56+
$0[.eq] = (Unidoc.AnyGroup[.scope], self.scope)
57+
}
4458
}
45-
$0.expr
59+
$0.append
4660
{
47-
$0[.gte] = (Unidoc.AnyGroup[.id], self.min)
61+
$0[.expr] = .expr
62+
{
63+
$0[.gte] = (Unidoc.AnyGroup[.id], self.min)
64+
}
4865
}
49-
$0.expr
66+
$0.append
5067
{
51-
$0[.lte] = (Unidoc.AnyGroup[.id], self.max)
68+
$0[.expr] = .expr
69+
{
70+
$0[.lte] = (Unidoc.AnyGroup[.id], self.max)
71+
}
5272
}
5373
}
5474
}

Sources/UnidocQueries/Volumes/Unidoc.LookupAdjacent.SpecialGroups.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,22 @@ extension Unidoc.LookupAdjacent
1414
extension Unidoc.LookupAdjacent.SpecialGroups
1515
{
1616
static
17-
func += (list:inout BSON.ListEncoder, self:Self)
17+
func += (or:inout Mongo.PredicateListEncoder, self:Self)
1818
{
1919
switch self
2020
{
2121
case .protocols:
2222
break
2323

2424
case .default(let self):
25-
list.expr { $0[.eq] = (Unidoc.AnyGroup[.id], self.peers) }
26-
list.expr { $0[.eq] = (Unidoc.AnyGroup[.id], self.topic) }
25+
or.append
26+
{
27+
$0[.expr] = .expr { $0[.eq] = (Unidoc.AnyGroup[.id], self.peers) }
28+
}
29+
or.append
30+
{
31+
$0[.expr] = .expr { $0[.eq] = (Unidoc.AnyGroup[.id], self.topic) }
32+
}
2733
}
2834
}
2935
}

Sources/UnidocQueries/Volumes/Unidoc.LookupAdjacent.Vertices.swift

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ extension Unidoc.LookupAdjacent
99
struct Vertices
1010
{
1111
private
12-
let layer:Unidoc.GroupLayerPredicate
12+
let layer:Unidoc.GroupLayer?
1313

1414
let groups:Mongo.List<Unidoc.AnyGroup, Mongo.KeyPath>
1515
let vertex:Mongo.KeyPath
1616

17-
init(layer:Unidoc.GroupLayerPredicate,
17+
init(layer:Unidoc.GroupLayer?,
1818
groups:Mongo.List<Unidoc.AnyGroup, Mongo.KeyPath>,
1919
vertex:Mongo.KeyPath)
2020
{
@@ -26,25 +26,22 @@ extension Unidoc.LookupAdjacent
2626
}
2727
}
2828
extension Unidoc.LookupAdjacent.Vertices
29+
{
30+
private
31+
var predicate:Unidoc.GroupLayerPredicate { .init(self.layer) }
32+
}
33+
extension Unidoc.LookupAdjacent.Vertices
2934
{
3035
static
3136
func += (list:inout BSON.ListEncoder, self:Self)
3237
{
33-
// Extract scalars adjacent to the current vertex.
34-
for array:Unidoc.AnyVertex.CodingKey in
35-
[
36-
.signature_expanded_scalars,
37-
.requirements,
38-
.superforms,
39-
.scope,
40-
]
38+
// Extract scalars adjacent to the list of vertex groups.
39+
list.expr
4140
{
42-
list.expr
43-
{
44-
$0[.coalesce] = (self.vertex / Unidoc.AnyVertex[array], [] as [Never])
45-
}
41+
$0[.reduce] = self.groups.flatMap(self.predicate.adjacent(to:))
4642
}
4743

44+
// Extract scalars adjacent to the current vertex.
4845
list.append
4946
{
5047
$0.append(self.vertex / Unidoc.AnyVertex[.namespace])
@@ -63,6 +60,29 @@ extension Unidoc.LookupAdjacent.Vertices
6360
$0[.map] = constraints.map { $0[.nominal] }
6461
}
6562

63+
let arrays:[Unidoc.AnyVertex.CodingKey]
64+
defer
65+
{
66+
for array:Unidoc.AnyVertex.CodingKey in arrays
67+
{
68+
list.expr
69+
{
70+
$0[.coalesce] = (self.vertex / Unidoc.AnyVertex[array], [] as [Never])
71+
}
72+
}
73+
}
74+
75+
switch self.layer
76+
{
77+
case nil:
78+
arrays = [.signature_expanded_scalars, .scope, .requirements, .superforms]
79+
80+
case .protocols?:
81+
arrays = [.signature_expanded_scalars, .scope]
82+
return
83+
}
84+
85+
// Only needed for the default layer.
6686
for passage:Unidoc.AnyVertex.CodingKey in [.overview, .details]
6787
{
6888
list.expr
@@ -73,11 +93,5 @@ extension Unidoc.LookupAdjacent.Vertices
7393
$0[.reduce] = outlines.flatMap(\.scalars)
7494
}
7595
}
76-
77-
// Extract scalars adjacent to the list of vertex groups.
78-
list.expr
79-
{
80-
$0[.reduce] = self.groups.flatMap(self.layer.adjacent(to:))
81-
}
8296
}
8397
}

Sources/UnidocQueries/Volumes/Unidoc.LookupAdjacent.swift

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ extension Unidoc
2020
}
2121
}
2222
}
23-
extension Unidoc.LookupAdjacent
24-
{
25-
private
26-
var predicate:Unidoc.GroupLayerPredicate { .init(self.layer) }
27-
}
2823
extension Unidoc.LookupAdjacent:Unidoc.LookupContext
2924
{
3025
public
@@ -45,11 +40,11 @@ extension Unidoc.LookupAdjacent:Unidoc.LookupContext
4540
default: special = .default(.init(peers: "peers", topic: "topic"))
4641
}
4742

48-
let local:LockedExtensions = .init(layer: self.predicate,
43+
let local:LockedExtensions = .init(layer: self.layer,
4944
scope: "local",
5045
min: "min",
5146
max: "max")
52-
let realm:LatestExtensions = .init(layer: self.predicate,
47+
let realm:LatestExtensions = .init(layer: self.layer,
5348
scope: "scope",
5449
id: "realm")
5550

@@ -108,14 +103,11 @@ extension Unidoc.LookupAdjacent:Unidoc.LookupContext
108103
{
109104
$0[.match] = .init
110105
{
111-
$0[.expr] = .expr
106+
$0[.or] = .init
112107
{
113-
$0[.or] = .init
114-
{
115-
$0 += special
116-
$0 += local
117-
$0 += realm
118-
}
108+
$0 += local
109+
$0 += realm
110+
$0 += special
119111
}
120112
}
121113
}
@@ -142,7 +134,7 @@ extension Unidoc.LookupAdjacent:Unidoc.LookupContext
142134
}
143135
$0[output.scalars] = .expr
144136
{
145-
let adjacent:Vertices = .init(layer: self.predicate,
137+
let adjacent:Vertices = .init(layer: self.layer,
146138
groups: .init(in: groups),
147139
vertex: vertex)
148140

0 commit comments

Comments
 (0)