Skip to content

Commit 15dd5d0

Browse files
committed
refactor linker actions into async functions
1 parent d581634 commit 15dd5d0

File tree

6 files changed

+118
-120
lines changed

6 files changed

+118
-120
lines changed

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: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,107 @@ extension Unidoc.DB.Snapshots
169169
}
170170
}
171171

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+
}
172273
extension Unidoc.DB.Snapshots
173274
{
174275
/// Returns a single batch of symbol graphs that are queued for linking.

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/UnidocServer/Operations/Interactions/Unidoc.LinkerOperation.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ extension Unidoc
1010
/// Queues one or more editions for uplinking. The uplinking process itself is asynchronous.
1111
struct LinkerOperation:Sendable
1212
{
13-
let queue:DB.Snapshots.QueueAction
13+
let action:LinkerAction
14+
let scope:Edition?
1415
let back:String?
1516

16-
init(queue:DB.Snapshots.QueueAction, back:String? = nil)
17+
init(action:Unidoc.LinkerAction, scope:Unidoc.Edition?, back:String? = nil)
1718
{
18-
self.queue = queue
19+
self.action = action
20+
self.scope = scope
1921
self.back = back
2022
}
2123
}
@@ -24,7 +26,7 @@ extension Unidoc.LinkerOperation
2426
{
2527
init(action:Unidoc.LinkerAction, form:Unidoc.LinkerForm)
2628
{
27-
self.init(queue: .one(form.edition, action: action), back: form.back)
29+
self.init(action: action, scope: form.edition, back: form.back)
2830
}
2931
}
3032
extension Unidoc.LinkerOperation:Unidoc.AdministrativeOperation
@@ -33,7 +35,15 @@ extension Unidoc.LinkerOperation:Unidoc.AdministrativeOperation
3335
db:Unidoc.DB,
3436
as _:Unidoc.RenderFormat) async throws -> HTTP.ServerResponse?
3537
{
36-
try await db.update(with: self.queue)
38+
if let scope:Unidoc.Edition = self.scope
39+
{
40+
try await db.snapshots.queue(id: scope, for: self.action)
41+
}
42+
else
43+
{
44+
try await db.snapshots.queueAll(for: self.action)
45+
}
46+
3747
return .redirect(.seeOther(self.back ?? "/admin"))
3848
}
3949
}

Sources/UnidocServer/Requests/Unidoc.Router.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ extension Unidoc.Router
646646
}
647647

648648
case .uplinkAll:
649-
return .unordered(Unidoc.LinkerOperation.init(queue: .all))
649+
return .unordered(Unidoc.LinkerOperation.init(action: .uplinkRefresh, scope: nil))
650650

651651
case .userConfig:
652652
if let account:Unidoc.Account = self.authorization.account,

0 commit comments

Comments
 (0)