Skip to content

Commit fd2bd0d

Browse files
committed
Replace some nasty and important code in DraftModel.saveToArticle, needs more testing
1 parent fc80d11 commit fd2bd0d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Diff for: Planet/Entities/DraftModel.swift

+22
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ class DraftModel: Identifiable, Equatable, Hashable, Codable, ObservableObject {
460460
planet.updated = Date()
461461
try planet.save()
462462

463+
/*
463464
Task(priority: .userInitiated) {
464465
try await planet.savePublic()
465466
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
@@ -475,6 +476,27 @@ class DraftModel: Identifiable, Equatable, Hashable, Codable, ObservableObject {
475476
}
476477
}
477478
}
479+
*/
480+
481+
// Code above is too nasty, let's try a new approach below
482+
Task(priority: .userInitiated) {
483+
do {
484+
try await planet.savePublic()
485+
486+
// Publish after a delay
487+
try await Task.sleep(nanoseconds: 500_000_000) // 0.5 seconds
488+
try await planet.publish()
489+
490+
// Prewarm article after a delay
491+
Task.detached {
492+
try await Task.sleep(nanoseconds: 3_000_000_000) // 3 seconds
493+
await article.prewarm()
494+
}
495+
} catch {
496+
// Handle errors appropriately
497+
print("During saving and publishing planet \(planet.name), an error occurred: \(error)")
498+
}
499+
}
478500

479501
Task { @MainActor in
480502
PlanetStore.shared.selectedView = .myPlanet(planet)

Diff for: Planet/versioning.xcconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
CURRENT_PROJECT_VERSION = 2290
1+
CURRENT_PROJECT_VERSION = 2292

0 commit comments

Comments
 (0)