mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-14 21:23:43 +01:00
added fake progress for lightweight migrations
This commit is contained in:
@@ -688,8 +688,35 @@ public extension DataStack {
|
||||
|
||||
do {
|
||||
|
||||
let timerQueue = DispatchQueue(
|
||||
label: "DataStack.lightweightMigration.timerQueue",
|
||||
qos: .utility,
|
||||
attributes: []
|
||||
)
|
||||
let estimatedTime: TimeInterval = 60 * 3 // 3 mins
|
||||
let interval: TimeInterval = 1
|
||||
let fakeTotalUnitCount: Float = 0.9 * Float(progress.totalUnitCount)
|
||||
var fakeProgress: Float = 0
|
||||
|
||||
var recursiveCheck: () -> Void = {}
|
||||
recursiveCheck = {
|
||||
|
||||
guard fakeProgress < 1 else {
|
||||
|
||||
return
|
||||
}
|
||||
progress.completedUnitCount = Int64(fakeTotalUnitCount * fakeProgress)
|
||||
fakeProgress += Float(interval / estimatedTime)
|
||||
|
||||
timerQueue.asyncAfter(
|
||||
deadline: .now() + interval,
|
||||
execute: recursiveCheck
|
||||
)
|
||||
}
|
||||
timerQueue.async(execute: recursiveCheck)
|
||||
|
||||
_ = try withExtendedLifetime(NSPersistentStoreCoordinator(managedObjectModel: destinationModel)) { (coordinator: NSPersistentStoreCoordinator) in
|
||||
|
||||
|
||||
try coordinator.addPersistentStoreSynchronously(
|
||||
type(of: storage).storeType,
|
||||
configuration: storage.configuration,
|
||||
@@ -699,6 +726,10 @@ public extension DataStack {
|
||||
)
|
||||
)
|
||||
}
|
||||
timerQueue.sync {
|
||||
|
||||
fakeProgress = 1
|
||||
}
|
||||
_ = try? storage.cs_finalizeStorageAndWait(soureModelHint: destinationModel)
|
||||
progress.completedUnitCount = progress.totalUnitCount
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user