mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-20 16:44:08 +01:00
added fake progress for lightweight migrations
This commit is contained in:
@@ -688,8 +688,35 @@ public extension DataStack {
|
|||||||
|
|
||||||
do {
|
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 withExtendedLifetime(NSPersistentStoreCoordinator(managedObjectModel: destinationModel)) { (coordinator: NSPersistentStoreCoordinator) in
|
||||||
|
|
||||||
try coordinator.addPersistentStoreSynchronously(
|
try coordinator.addPersistentStoreSynchronously(
|
||||||
type(of: storage).storeType,
|
type(of: storage).storeType,
|
||||||
configuration: storage.configuration,
|
configuration: storage.configuration,
|
||||||
@@ -699,6 +726,10 @@ public extension DataStack {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
timerQueue.sync {
|
||||||
|
|
||||||
|
fakeProgress = 1
|
||||||
|
}
|
||||||
_ = try? storage.cs_finalizeStorageAndWait(soureModelHint: destinationModel)
|
_ = try? storage.cs_finalizeStorageAndWait(soureModelHint: destinationModel)
|
||||||
progress.completedUnitCount = progress.totalUnitCount
|
progress.completedUnitCount = progress.totalUnitCount
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user