Skip to content

Commit f1c51dc

Browse files
committed
fix decoding error
1 parent 66cb530 commit f1c51dc

File tree

4 files changed

+42
-49
lines changed

4 files changed

+42
-49
lines changed

Sources/UnidocDB/Unidoc.DB.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,19 @@ extension Unidoc.DB
460460
{
461461
// We assume compressing the search JSON will take a (relatively) long time, so we do
462462
// it before performing any database operations.
463+
//
464+
// Our gzip compression is about 1.5 percent worse than Amazon CloudFront’s
465+
// compression, which uses the Brotli algorithm. But it saves us local disk space,
466+
// because we always store a copy of the search index in the database.
467+
//
468+
// Amazon CloudFront will not re-compress files we have already compressed, so this
469+
// means users will need to download 1.5 percent more data to use the search index.
470+
// We think this is an acceptable trade-off, because compressing the search index
471+
// locally means we can add more symbols to each search index.
472+
//
473+
// We could get the best of both worlds by decompressing the search index before
474+
// transferring it out to Amazon CloudFront. But that just doesn’t seem worth the CPU
475+
// cycles, either for us or for Amazon.
463476
let search:Unidoc.TextResource<Symbol.Edition> = .init(id: volume.id,
464477
text: .init(compressing: volume.index.utf8))
465478

Sources/UnidocQueries/Search/Unidoc.TextResourceOutput.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ extension Unidoc.TextResourceOutput:MongoMasterCodingModel
2727
@frozen public
2828
enum CodingKey:String, Sendable
2929
{
30-
case text = "J"
31-
case hash = "H"
30+
case text
31+
case hash
3232
}
3333
}
3434
extension Unidoc.TextResourceOutput:BSONDocumentDecodable

Sources/UnidocQueries/Search/Unidoc.TextResourceQuery.swift

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -44,57 +44,44 @@ extension Unidoc.TextResourceQuery:Mongo.PipelineQuery
4444
public
4545
func build(pipeline:inout Mongo.PipelineEncoder)
4646
{
47-
pipeline[stage: .match] = .init
48-
{
49-
$0[Unidoc.TextResource<CollectionOrigin.Element.ID>[.id]] = self.id
50-
}
47+
typealias Document = Unidoc.TextResource<CollectionOrigin.Element.ID>
5148

52-
guard
53-
let tag:MD5 = self.tag
54-
else
49+
pipeline[stage: .match] = .init
5550
{
56-
return
51+
$0[Document[.id]] = self.id
5752
}
5853

5954
pipeline[stage: .set] = .init
6055
{
61-
$0[Unidoc.TextResourceOutput[.hash]] =
62-
Unidoc.TextResource<CollectionOrigin.Element.ID>[.hash]
63-
56+
$0[Unidoc.TextResourceOutput[.hash]] = Document[.hash]
6457
$0[Unidoc.TextResourceOutput[.text]] = .expr
6558
{
66-
$0[.cond] =
67-
(
68-
if: .expr
69-
{
70-
$0[.eq] =
71-
(
72-
tag,
73-
Unidoc.TextResource<CollectionOrigin.Element.ID>[.hash]
74-
)
75-
},
76-
then: .expr
77-
{
78-
$0[.binarySize] = .expr
59+
if let tag:MD5 = self.tag
60+
{
61+
$0[.cond] =
62+
(
63+
if: .expr
64+
{
65+
$0[.eq] = (tag, Document[.hash])
66+
},
67+
then: .expr
7968
{
80-
$0[.coalesce] =
81-
(
82-
Unidoc.TextResource<CollectionOrigin.Element.ID>[.gzip],
83-
Unidoc.TextResource<CollectionOrigin.Element.ID>[.utf8]
84-
)
69+
$0[.binarySize] = .expr
70+
{
71+
$0[.coalesce] = (Document[.gzip], Document[.utf8])
72+
}
73+
},
74+
else: .expr
75+
{
76+
$0[.coalesce] = (Document[.gzip], Document[.utf8])
8577
}
86-
},
87-
else: .expr
88-
{
89-
$0[.coalesce] =
90-
(
91-
Unidoc.TextResource<CollectionOrigin.Element.ID>[.gzip],
92-
Unidoc.TextResource<CollectionOrigin.Element.ID>[.utf8]
93-
)
94-
}
95-
)
78+
)
79+
}
80+
else
81+
{
82+
$0[.coalesce] = (Document[.gzip], Document[.utf8])
83+
}
9684
}
9785
}
9886
}
9987
}
100-

Sources/UnidocRecords/Volumes/Unidoc.Volume.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@ extension Unidoc.Volume
5151
}
5252
extension Unidoc.Volume
5353
{
54-
@available(*, deprecated)
55-
@inlinable public
56-
var search:Unidoc.TextResource<Symbol.Edition>
57-
{
58-
.init(id: self.id, text: .utf8(self.index.utf8[...]))
59-
}
60-
6154
public
6255
func sitemap() -> Unidoc.Sitemap
6356
{

0 commit comments

Comments
 (0)