@@ -72,6 +72,8 @@ extension UnidocDatabase:DatabaseModel
72
72
try await self . siteMaps. setup ( with: session)
73
73
}
74
74
}
75
+
76
+ @available ( * , unavailable, message: " unused " )
75
77
extension UnidocDatabase
76
78
{
77
79
private
@@ -84,39 +86,96 @@ extension UnidocDatabase
84
86
try await self . names. replace ( with: session)
85
87
try await self . siteMaps. replace ( with: session)
86
88
}
87
- }
88
- extension UnidocDatabase
89
- {
90
- // TODO: we need to get out of the habit of performing database-wide rebuilds;
91
- // this procedure should be deprecated!
92
- public
93
- func _rebuild( with session: __shared Mongo. Session ) async throws -> Int
89
+
90
+ func _editions( of package : PackageIdentifier ,
91
+ with session: Mongo . Session ) async throws -> [ PackageEdition ]
94
92
{
95
- // TODO: we need to implement some kind of locking mechanism to prevent
96
- // race conditions between rebuilds and pushes. This cannot be done with
97
- // MongoDB transactions because deleting a very large number of records
98
- // overflows the transaction cache.
99
- try await self . _clear ( with: session)
93
+ try await session. run (
94
+ command: Mongo . Aggregate< Mongo . Cursor< PackageEdition>>. init( Packages . name,
95
+ pipeline: . init
96
+ {
97
+ $0. stage
98
+ {
99
+ $0 [ . match] = . init
100
+ {
101
+ $0 [ PackageRecord [ . id] ] = package
102
+ }
103
+ }
100
104
101
- print ( " cleared all unidoc volumes... " )
105
+ let editions : Mongo . KeyPath = " editions "
102
106
103
- // var origins:[Int32: Volume.Origin?] = [:]
104
- var count : Int = 0
107
+ $0. stage
108
+ {
109
+ $0 [ . lookup] = . init
110
+ {
111
+ $0 [ . from] = Editions . name
112
+ $0 [ . localField] = PackageRecord [ . cell]
113
+ $0 [ . foreignField] = PackageEdition [ . package ]
114
+ $0 [ . as] = editions
115
+ }
116
+ }
105
117
106
- try await self . graphs. list ( with: session)
107
- {
108
- ( snapshot: Snapshot ) in
118
+ $0. stage
119
+ {
120
+ $0 [ . lookup] = . init
121
+ {
122
+ let cell : Mongo . Variable < Int32 > = " cell "
109
123
110
- let volume : Volume = try await self . link ( snapshot, with: session)
124
+ $0 [ . from] = Graphs . name
125
+ $0 [ . let] = . init
126
+ {
127
+ $0 [ let: cell] = PackageRecord [ . cell]
128
+ }
129
+ $0 [ . pipeline] = . init
130
+ {
131
+ $0. stage
132
+ {
133
+ $0 [ . match] = . init
134
+ {
135
+ $0 [ . expr] = . expr
136
+ {
137
+ $0 [ . eq] = ( Snapshot [ . package ] , cell)
138
+ }
139
+ }
140
+ }
111
141
112
- try await self . publish ( volume, with: session)
142
+ $0. stage
143
+ {
144
+ $0 [ . sort] = . init
145
+ {
146
+ $0 [ Snapshot [ . version] ] = ( - )
147
+ }
148
+ }
113
149
114
- count += 1
150
+ $0. stage
151
+ {
152
+ $0 [ . limit] = 1
153
+ }
115
154
116
- print ( " regenerated records for snapshot: \( snapshot. id) " )
117
- }
155
+ $0. stage
156
+ {
157
+ $0 [ . replaceWith] = Snapshot [ . metadata]
158
+ }
159
+ }
160
+ $0 [ . as] = " recent "
161
+ }
162
+ }
163
+
164
+ $0. stage
165
+ {
166
+ $0 [ . unwind] = editions
167
+ }
118
168
119
- return count
169
+ $0. stage
170
+ {
171
+ $0 [ . replaceWith] = editions
172
+ }
173
+ } ,
174
+ stride: 1 ) ,
175
+ against: self . id)
176
+ {
177
+ try await $0. reduce ( into: [ ] , += )
178
+ }
120
179
}
121
180
}
122
181
@@ -209,135 +268,72 @@ extension UnidocDatabase
209
268
repo: placement. repo)
210
269
}
211
270
}
212
- extension UnidocDatabase
213
- {
214
- @available ( * , unavailable, message: " unused " )
215
- func _editions( of package : PackageIdentifier ,
216
- with session: Mongo . Session ) async throws -> [ PackageEdition ]
217
- {
218
- try await session. run (
219
- command: Mongo . Aggregate< Mongo . Cursor< PackageEdition>>. init( Packages . name,
220
- pipeline: . init
221
- {
222
- $0. stage
223
- {
224
- $0 [ . match] = . init
225
- {
226
- $0 [ PackageRecord [ . id] ] = package
227
- }
228
- }
229
-
230
- let editions : Mongo . KeyPath = " editions "
231
-
232
- $0. stage
233
- {
234
- $0 [ . lookup] = . init
235
- {
236
- $0 [ . from] = Editions . name
237
- $0 [ . localField] = PackageRecord [ . cell]
238
- $0 [ . foreignField] = PackageEdition [ . package ]
239
- $0 [ . as] = editions
240
- }
241
- }
242
-
243
- $0. stage
244
- {
245
- $0 [ . lookup] = . init
246
- {
247
- let cell : Mongo . Variable < Int32 > = " cell "
248
-
249
- $0 [ . from] = Graphs . name
250
- $0 [ . let] = . init
251
- {
252
- $0 [ let: cell] = PackageRecord [ . cell]
253
- }
254
- $0 [ . pipeline] = . init
255
- {
256
- $0. stage
257
- {
258
- $0 [ . match] = . init
259
- {
260
- $0 [ . expr] = . expr
261
- {
262
- $0 [ . eq] = ( Snapshot [ . package ] , cell)
263
- }
264
- }
265
- }
266
-
267
- $0. stage
268
- {
269
- $0 [ . sort] = . init
270
- {
271
- $0 [ Snapshot [ . version] ] = ( - )
272
- }
273
- }
274
-
275
- $0. stage
276
- {
277
- $0 [ . limit] = 1
278
- }
279
-
280
- $0. stage
281
- {
282
- $0 [ . replaceWith] = Snapshot [ . metadata]
283
- }
284
- }
285
- $0 [ . as] = " recent "
286
- }
287
- }
288
-
289
- $0. stage
290
- {
291
- $0 [ . unwind] = editions
292
- }
293
-
294
- $0. stage
295
- {
296
- $0 [ . replaceWith] = editions
297
- }
298
- } ,
299
- stride: 1 ) ,
300
- against: self . id)
301
- {
302
- try await $0. reduce ( into: [ ] , += )
303
- }
304
- }
305
- }
306
271
307
272
extension UnidocDatabase
308
273
{
309
274
public
310
- func publish( linking docs: __owned SymbolGraphArchive,
275
+ func publish( _ docs: __owned SymbolGraphArchive,
311
276
with session: Mongo . Session ) async throws -> SnapshotReceipt
312
277
{
313
278
let receipt : SnapshotReceipt = try await self . store ( docs: docs, with: session)
279
+
314
280
let volume : Volume = try await self . link ( . init(
315
281
package : receipt. package ,
316
282
version: receipt. version,
317
283
metadata: docs. metadata,
318
284
graph: docs. graph) ,
319
285
with: session)
320
286
321
- if case . update = receipt. type
322
- {
323
- try await self . search. delete ( volume. id, with: session)
287
+ _ = consume docs
324
288
325
- try await self . vertices. clear ( receipt. edition, with: session)
326
- try await self . groups. clear ( receipt. edition, with: session)
327
- try await self . trees. clear ( receipt. edition, with: session)
289
+ try await self . fill ( volume: consume volume,
290
+ clear: receipt. type == . update,
291
+ with: session)
292
+
293
+ return receipt
294
+ }
328
295
329
- try await self . names. delete ( receipt. edition, with: session)
296
+ public
297
+ func uplink(
298
+ package : Int32 ,
299
+ version: Int32 ? ,
300
+ with session: Mongo . Session ) async throws -> Int
301
+ {
302
+ var uplinked : Int = 0
303
+
304
+ try await self . graphs. list (
305
+ filter: ( package : package , version: version) ,
306
+ with: session)
307
+ {
308
+ try await self . fill (
309
+ volume: try await self . link ( $0, with: session) ,
310
+ clear: true ,
311
+ with: session)
312
+
313
+ uplinked += 1
330
314
}
331
315
332
- try await self . publish ( volume, with: session)
333
- return receipt
316
+ return uplinked
334
317
}
335
318
}
336
319
extension UnidocDatabase
337
320
{
338
321
private
339
- func publish( _ volume: __owned Volume, with session: __shared Mongo. Session ) async throws
322
+ func fill( volume: __owned Volume,
323
+ clear: Bool = true ,
324
+ with session: Mongo . Session ) async throws
340
325
{
326
+ if clear
327
+ {
328
+ try await self . search. delete ( volume. id, with: session)
329
+
330
+ try await self . vertices. clear ( volume. edition, with: session)
331
+ try await self . groups. clear ( volume. edition, with: session)
332
+ try await self . trees. clear ( volume. edition, with: session)
333
+
334
+ try await self . names. delete ( volume. edition, with: session)
335
+ }
336
+
341
337
let ( index, trees) : ( SearchIndex < VolumeIdentifier > , [ Volume . TypeTree ] ) = volume. indexes ( )
342
338
343
339
try await self . vertices. insert ( some: volume. vertices, with: session)
@@ -416,8 +412,8 @@ extension UnidocDatabase
416
412
extension UnidocDatabase
417
413
{
418
414
public
419
- func siteMap( package : __owned PackageIdentifier,
420
- with session: __shared Mongo. Session ) async throws -> Volume . SiteMap < PackageIdentifier > ?
415
+ func siteMap( package : consuming PackageIdentifier ,
416
+ with session: Mongo . Session ) async throws -> Volume . SiteMap < PackageIdentifier > ?
421
417
{
422
418
try await self . siteMaps. find ( by: package , with: session)
423
419
}
0 commit comments