Skip to content

Commit c71579c

Browse files
authored
Merge pull request #342 from tayloraswift/mark-vintage
Mark vintage symbol graphs
2 parents 3d50dc6 + edbae77 commit c71579c

File tree

11 files changed

+188
-137
lines changed

11 files changed

+188
-137
lines changed

Sources/UnidocAPI/Building/Unidoc.LinkerRoute.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ extension Unidoc
66
case uplink
77
case unlink
88
case delete
9+
/// This is not really a linker action, but it is related closely enough to piggyback
10+
/// on the same route.
11+
case vintage
912
}
1013
}
1114
extension Unidoc.LinkerRoute:CustomStringConvertible

Sources/UnidocDB/Snapshots/Unidoc.DB.Snapshots.ClearAction.swift

Lines changed: 0 additions & 43 deletions
This file was deleted.

Sources/UnidocDB/Snapshots/Unidoc.DB.Snapshots.QueueAction.swift

Lines changed: 0 additions & 69 deletions
This file was deleted.

Sources/UnidocDB/Snapshots/Unidoc.DB.Snapshots.swift

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ extension Unidoc.DB.Snapshots
4040
}
4141

4242
public static
43-
let indexSymbolGraphABI:Mongo.CollectionIndex = .init("ABI",
43+
let indexSymbolGraphABI:Mongo.CollectionIndex = .init("ABI/2",
4444
unique: false)
4545
{
46+
$0[Unidoc.Snapshot[.vintage]] = (+)
4647
$0[Unidoc.Snapshot[.metadata] / SymbolGraphMetadata[.abi]] = (+)
4748
}
4849

@@ -168,6 +169,107 @@ extension Unidoc.DB.Snapshots
168169
}
169170
}
170171

172+
extension Unidoc.DB.Snapshots
173+
{
174+
@discardableResult
175+
public
176+
func queueAll(for action:Unidoc.LinkerAction) async throws -> Int
177+
{
178+
try await self.updateMany
179+
{
180+
$0
181+
{
182+
$0[.multi] = true
183+
$0[.q]
184+
{
185+
$0[Unidoc.Snapshot[.action]] { $0[.exists] = false }
186+
}
187+
$0[.u]
188+
{
189+
$0[.set]
190+
{
191+
$0[Unidoc.Snapshot[.action]] = action
192+
}
193+
}
194+
}
195+
}
196+
}
197+
198+
@discardableResult
199+
public
200+
func queue(id:Unidoc.Edition, for action:Unidoc.LinkerAction) async throws -> Bool?
201+
{
202+
try await self.update
203+
{
204+
$0
205+
{
206+
$0[.q]
207+
{
208+
$0[Unidoc.Snapshot[.action]] { $0[.exists] = false }
209+
$0[Unidoc.Snapshot[.id]] = id
210+
}
211+
$0[.u]
212+
{
213+
$0[.set]
214+
{
215+
$0[Unidoc.Snapshot[.action]] = action
216+
}
217+
}
218+
}
219+
}
220+
}
221+
222+
/// Clears the **queued action** for a single snapshot. Does not delete the snapshot!
223+
@discardableResult
224+
public
225+
func clear(id:Unidoc.Edition) async throws -> Bool?
226+
{
227+
try await self.update
228+
{
229+
$0
230+
{
231+
$0[.q] { $0[Unidoc.Snapshot[.id]] = id }
232+
$0[.u]
233+
{
234+
$0[.unset]
235+
{
236+
$0[Unidoc.Snapshot[.action]] = ()
237+
}
238+
}
239+
}
240+
}
241+
}
242+
243+
@discardableResult
244+
public
245+
func mark(id:Unidoc.Edition, vintage:Bool) async throws -> Bool?
246+
{
247+
try await self.update
248+
{
249+
$0
250+
{
251+
$0[.q] { $0[Unidoc.Snapshot[.id]] = id }
252+
$0[.u]
253+
{
254+
if vintage
255+
{
256+
$0[.set]
257+
{
258+
$0[Unidoc.Snapshot[.vintage]] = true
259+
}
260+
}
261+
else
262+
{
263+
$0[.unset]
264+
{
265+
$0[Unidoc.Snapshot[.vintage]] = ()
266+
}
267+
}
268+
}
269+
}
270+
}
271+
}
272+
}
171273
extension Unidoc.DB.Snapshots
172274
{
173275
/// Returns a single batch of symbol graphs that are queued for linking.
@@ -207,6 +309,9 @@ extension Unidoc.DB.Snapshots
207309
{
208310
$0[.filter]
209311
{
312+
// This needs to be ``BSON.Null`` and not just `{ $0[.exists] = false }`,
313+
// otherwise it will not use the partial index.
314+
$0[Unidoc.Snapshot[.vintage]] = BSON.Null.init()
210315
$0[Unidoc.Snapshot[.metadata] / SymbolGraphMetadata[.abi]]
211316
{
212317
$0[.lt] = version

Sources/UnidocLinkerPlugin/Unidoc.GraphLinker.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ extension Unidoc.GraphLinker
136136
}
137137
}
138138

139-
try await context.db.update(
140-
with: Unidoc.DB.Snapshots.ClearAction.one(operation.edition))
139+
try await context.db.snapshots.clear(id: operation.edition)
141140

142141
if let event:Event
143142
{

Sources/UnidocRecords/Packages/Unidoc.Snapshot.swift

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,34 @@ extension Unidoc
3939
public
4040
var size:Int64
4141

42-
@inlinable internal
42+
/// Indicates if the symbol graph is no longer buildable from source. This flag prevents
43+
/// the automated build system from repeatedly attempting to build the package.
44+
///
45+
/// Possible reasons for this include:
46+
///
47+
/// - The package no longer compiles using the latest version of its dependencies,
48+
/// and its manifest does not constrain the dependencies to compatible versions.
49+
///
50+
/// - The package, or one of its dependencies, has been taken down from GitHub.
51+
///
52+
/// - The package only builds on a platform that is no longer supported by the hosting
53+
/// service.
54+
///
55+
/// - The package suffers from a Swift (or Unidoc) compiler bug that prevents it from
56+
/// being built.
57+
public
58+
var vintage:Bool
59+
60+
@inlinable
4361
init(id:Edition,
4462
metadata:SymbolGraphMetadata,
4563
inline:SymbolGraph?,
4664
action:LinkerAction?,
4765
swift:PatchVersion?,
4866
pins:[Edition?],
4967
type:GraphType,
50-
size:Int64)
68+
size:Int64,
69+
vintage:Bool)
5170
{
5271
self.id = id
5372
self.metadata = metadata
@@ -57,6 +76,7 @@ extension Unidoc
5776
self.pins = pins
5877
self.type = type
5978
self.size = size
79+
self.vintage = vintage
6080
}
6181
}
6282
}
@@ -87,7 +107,8 @@ extension Unidoc.Snapshot
87107
swift: swift,
88108
pins: [],
89109
type: .bson,
90-
size: 0)
110+
size: 0,
111+
vintage: false)
91112
}
92113
}
93114
extension Unidoc.Snapshot
@@ -155,6 +176,7 @@ extension Unidoc.Snapshot
155176
case pins = "p"
156177
case type = "T"
157178
case size = "B"
179+
case vintage = "V"
158180

159181
@available(*, deprecated, renamed: "inline")
160182
@inlinable public static
@@ -179,6 +201,7 @@ extension Unidoc.Snapshot:BSONDocumentEncodable
179201
bson[.pins] = self.pins.isEmpty ? nil : self.pins
180202
bson[.type] = self.type
181203
bson[.size] = self.size
204+
bson[.vintage] = self.vintage ? true : nil
182205
}
183206
}
184207
extension Unidoc.Snapshot:BSONDocumentDecodable
@@ -193,6 +216,7 @@ extension Unidoc.Snapshot:BSONDocumentDecodable
193216
swift: try bson[.swift]?.decode(),
194217
pins: try bson[.pins]?.decode() ?? [],
195218
type: try bson[.type]?.decode() ?? .bson,
196-
size: try bson[.size]?.decode() ?? 0)
219+
size: try bson[.size]?.decode() ?? 0,
220+
vintage: try bson[.vintage]?.decode() ?? false)
197221
}
198222
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
extension Unidoc.LinkerOperation
2+
{
3+
enum Update
4+
{
5+
case action(Unidoc.LinkerAction)
6+
case vintage(Bool)
7+
}
8+
}

0 commit comments

Comments
 (0)