Skip to content

Commit e98566c

Browse files
committed
naturally, we were working on the wrong code
1 parent d677198 commit e98566c

File tree

10 files changed

+128
-113
lines changed

10 files changed

+128
-113
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ extension Unidoc.DB.Redirects
2828
collation: VolumeCollation.spec,
2929
unique: true)
3030
{
31-
$0[Element[.id] / Unidoc.Redirect[.volume]] = (+)
32-
$0[Element[.stem]] = (+)
33-
$0[Element[.hash]] = (+)
31+
$0[Element[.id] / Unidoc.RedirectSource[.volume]] = (+)
32+
$0[Element[.id] / Unidoc.RedirectSource[.stem]] = (+)
33+
$0[Element[.id] / Unidoc.RedirectSource[.hash]] = (+)
3434
}
3535
}
3636
extension Unidoc.DB.Redirects:Mongo.CollectionModel
@@ -54,7 +54,7 @@ extension Unidoc.DB.Redirects
5454
{
5555
try await self.deleteAll
5656
{
57-
$0[Element[.id] / Unidoc.Redirect[.volume]] = volume
57+
$0[Element[.id] / Unidoc.RedirectSource[.volume]] = volume
5858
}
5959
}
6060
}

Sources/UnidocDB/Vertices/Unidoc.Redirect (ext).swift

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import MongoQL
2+
import UnidocRecords
3+
4+
extension Unidoc.RedirectSource:Mongo.MasterCodingModel
5+
{
6+
}

Sources/UnidocLinker/Sema/Unidoc.Linker.Tables.swift

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ extension Unidoc.Linker
3636

3737
private(set)
3838
var extensions:Unidoc.Linker.Table<Unidoc.Extension>
39-
var redirects:[Unidoc.RedirectVertex]
4039
var articles:[Unidoc.ArticleVertex]
4140
var decls:[Unidoc.DeclVertex]
4241

@@ -60,7 +59,6 @@ extension Unidoc.Linker
6059
self.next = .init(base: self.context.current.id)
6160

6261
self.extensions = extensions
63-
self.redirects = []
6462
self.articles = []
6563
self.decls = []
6664

@@ -390,10 +388,6 @@ extension Unidoc.Linker.Tables
390388
{
391389
self.link(articles: articles, under: namespace)
392390
}
393-
394-
// Create redirects
395-
self.redirect(decls: culture.reexports.unhashed, hashed: false, from: namespace)
396-
self.redirect(decls: culture.reexports.hashed, hashed: true, from: namespace)
397391
}
398392

399393
return self.modules.map
@@ -554,32 +548,4 @@ extension Unidoc.Linker.Tables
554548

555549
return miscellaneous
556550
}
557-
558-
private mutating
559-
func redirect(decls:[Int32],
560-
hashed:Bool,
561-
from namespace:SymbolGraph.NamespaceContext<Void>)
562-
{
563-
for local:Int32 in decls
564-
{
565-
let symbol:Symbol.Decl = self.current.decls.symbols[local]
566-
567-
guard
568-
let id:Unidoc.Scalar = self.current.scalars.decls[local],
569-
let decl:SymbolGraph.Decl = self.context[decl: id]
570-
else
571-
{
572-
continue
573-
}
574-
575-
let redirect:Unidoc.RedirectVertex = .init(id: .init(
576-
volume: self.current.id,
577-
target: id),
578-
stem: .decl(namespace.module, decl.path, decl.phylum),
579-
hash: .decl(symbol),
580-
hashed: hashed)
581-
582-
self.redirects.append(redirect)
583-
}
584-
}
585551
}

Sources/UnidocLinker/Sema/Unidoc.LinkerTables.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,52 @@ extension Unidoc.LinkerTables
379379
return vertex
380380
}
381381
}
382+
383+
func linkRedirects() -> [Unidoc.RedirectVertex]
384+
{
385+
self.modules.reduce(into: [])
386+
{
387+
for (decls, hashed):([Int32], Bool) in [
388+
($1.culture.reexports.unhashed, false),
389+
($1.culture.reexports.hashed, true),
390+
]
391+
{
392+
for target:Int32 in decls
393+
{
394+
if let vertex:Unidoc.RedirectVertex = self.linkRedirect(
395+
target: target,
396+
hashed: hashed,
397+
from: $1.symbol)
398+
{
399+
$0.append(vertex)
400+
}
401+
}
402+
}
403+
}
404+
}
405+
406+
private
407+
func linkRedirect(
408+
target local:Int32,
409+
hashed:Bool,
410+
from namespace:Symbol.Module) -> Unidoc.RedirectVertex?
411+
{
412+
let symbol:Symbol.Decl = self.current.decls.symbols[local]
413+
414+
guard
415+
let id:Unidoc.Scalar = self.current.scalars.decls[local],
416+
let decl:SymbolGraph.Decl = self.linker[decl: id]
417+
else
418+
{
419+
return nil
420+
}
421+
422+
return .init(id: .init(volume: self.current.id,
423+
stem: .decl(namespace, decl.path, decl.phylum),
424+
hash: .decl(symbol)),
425+
target: id,
426+
hashed: hashed)
427+
}
382428
}
383429
extension Unidoc.LinkerTables
384430
{

Sources/UnidocLinker/Unidoc.Mesh.Interior.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ extension Unidoc.Mesh.Interior
8888
products = tables.linkProducts()
8989
cultures = tables.linkCultures()
9090

91-
redirects = tables.redirects
91+
redirects = []
9292
articles = tables.articles
9393
decls = tables.decls
9494
groups = tables.groups
@@ -109,9 +109,9 @@ extension Unidoc.Mesh.Interior
109109
decls = tables.linkDecls()
110110
articles = tables.linkArticles()
111111
cultures = tables.linkCultures()
112+
redirects = tables.linkRedirects()
112113

113114
extensions = tables.extensions
114-
redirects = []
115115
groups = tables.groups
116116

117117
linker = tables.linker

Sources/UnidocQueries/Volumes/Unidoc.RedirectByExportQuery.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ extension Unidoc.RedirectByExportQuery:Mongo.PipelineQuery
3333
{
3434
pipeline[stage: .match]
3535
{
36-
$0[CollectionOrigin.Element[.id] / Unidoc.Redirect[.volume]] = self.volume
37-
$0[CollectionOrigin.Element[.stem]] = self.stem
38-
$0[CollectionOrigin.Element[.hash]] = self.hash
36+
$0[CollectionOrigin.Element[.id] / Unidoc.RedirectSource[.volume]] = self.volume
37+
$0[CollectionOrigin.Element[.id] / Unidoc.RedirectSource[.stem]] = self.stem
38+
$0[CollectionOrigin.Element[.id] / Unidoc.RedirectSource[.hash]] = self.hash
3939
}
4040

4141
pipeline[stage: .limit] = 1
@@ -62,7 +62,7 @@ extension Unidoc.RedirectByExportQuery:Mongo.PipelineQuery
6262
pipeline[stage: .lookup]
6363
{
6464
$0[.from] = Unidoc.DB.Vertices.name
65-
$0[.localField] = CollectionOrigin.Element[.id] / Unidoc.Redirect[.target]
65+
$0[.localField] = CollectionOrigin.Element[.target]
6666
$0[.foreignField] = Unidoc.AnyVertex[.id]
6767
$0[.as] = Iteration.BatchElement[.matches]
6868
}

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

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import FNV1
2+
import BSON
3+
import UnidocAPI
4+
5+
extension Unidoc
6+
{
7+
@frozen public
8+
struct RedirectSource:Hashable, Sendable
9+
{
10+
public
11+
let volume:Edition
12+
public
13+
let stem:Stem
14+
/// We don’t have any reason to correlate redirects themselves across volumes.
15+
/// Therefore, we store only the 24-bit hash, to simplify queries.
16+
public
17+
let hash:FNV24
18+
19+
@inlinable public
20+
init(volume:Edition, stem:Stem, hash:FNV24)
21+
{
22+
self.volume = volume
23+
self.stem = stem
24+
self.hash = hash
25+
}
26+
}
27+
}
28+
extension Unidoc.RedirectSource
29+
{
30+
@frozen public
31+
enum CodingKey:String, Sendable
32+
{
33+
case volume = "V"
34+
case stem = "U"
35+
case hash = "H"
36+
}
37+
}
38+
extension Unidoc.RedirectSource:BSONDocumentEncodable
39+
{
40+
public
41+
func encode(to document:inout BSON.DocumentEncoder<CodingKey>)
42+
{
43+
document[.volume] = self.volume
44+
document[.stem] = self.stem
45+
document[.hash] = self.hash
46+
}
47+
}
48+
extension Unidoc.RedirectSource:BSONDocumentDecodable
49+
{
50+
public
51+
init(bson:BSON.DocumentDecoder<CodingKey>) throws
52+
{
53+
self.init(volume: try bson[.volume].decode(),
54+
stem: try bson[.stem].decode(),
55+
hash: try bson[.hash].decode())
56+
}
57+
}

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

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,17 @@ extension Unidoc
88
struct RedirectVertex:Identifiable
99
{
1010
public
11-
let id:Redirect
11+
let id:RedirectSource
1212
public
13-
let stem:Stem
14-
/// We don’t have any reason to correlate redirects themselves across volumes.
15-
/// Therefore, we store only the 24-bit hash, to simplify queries.
16-
public
17-
let hash:FNV24
13+
let target:Scalar
1814
public
1915
let hashed:Bool
2016

2117
@inlinable public
22-
init(id:Redirect, stem:Stem, hash:FNV24, hashed:Bool)
18+
init(id:RedirectSource, target:Scalar, hashed:Bool)
2319
{
2420
self.id = id
25-
self.stem = stem
26-
self.hash = hash
21+
self.target = target
2722
self.hashed = hashed
2823
}
2924
}
@@ -34,8 +29,7 @@ extension Unidoc.RedirectVertex
3429
enum CodingKey:String, Sendable
3530
{
3631
case id = "_id"
37-
case stem = "U"
38-
case hash = "F"
32+
case target = "T"
3933
case hashed = "H"
4034
/// The target volume, omitted in the schema if it matches the source volume. It is
4135
/// omitted because in that case, it can be computed from the target vertex coordinate.
@@ -48,12 +42,11 @@ extension Unidoc.RedirectVertex:BSONDocumentEncodable
4842
func encode(to document:inout BSON.DocumentEncoder<CodingKey>)
4943
{
5044
document[.id] = self.id
51-
document[.stem] = self.stem
52-
document[.hash] = self.hash
45+
document[.target] = self.target
5346
document[.hashed] = self.hashed ? true : nil
5447

55-
document[.volume] = self.id.volume != self.id.target.edition
56-
? self.id.target.edition
48+
document[.volume] = self.id.volume != self.target.edition
49+
? self.target.edition
5750
: nil
5851
}
5952
}
@@ -63,8 +56,7 @@ extension Unidoc.RedirectVertex:BSONDocumentDecodable
6356
init(bson:BSON.DocumentDecoder<CodingKey>) throws
6457
{
6558
self.init(id: try bson[.id].decode(),
66-
stem: try bson[.stem].decode(),
67-
hash: try bson[.hash].decode(),
59+
target: try bson[.target].decode(),
6860
hashed: try bson[.hashed]?.decode() ?? false)
6961
}
7062
}

0 commit comments

Comments
 (0)