Fix ANR al terminar el import CSV (save + widget refresh por cada fila)
createSnapshot hacía save() por cada snapshot, y save() dispara refreshWidgetData → checkpointWAL (performAndWait en el viewContext main) + reloadAllTimelines. Con 213 snapshots eran 213 saves + 213 checkpoints en el main → Application Not Responding. Añadido modo batch a createSnapshot (no guarda por fila; applyImport ya guarda el contexto una vez al final) y flag suppressWidgetRefresh en CoreDataStack para neutralizar el refresh por fila durante el import, con un único refreshWidgetData al terminar. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L2p3gUZRNWW388rWFRjiU7
This commit is contained in:
@@ -383,6 +383,15 @@ Personal,Real Estate,Rental Property,2024-01-01,82000,80000,Estimated value
|
||||
let sourceRepository = InvestmentSourceRepository(context: context)
|
||||
let snapshotRepository = SnapshotRepository(context: context)
|
||||
|
||||
// Batch import: suppress the per-row widget refresh (each does a synchronous
|
||||
// WAL checkpoint on the main context) to avoid hanging the main thread on
|
||||
// large imports. Refresh once when everything is done.
|
||||
CoreDataStack.shared.suppressWidgetRefresh = true
|
||||
defer {
|
||||
CoreDataStack.shared.suppressWidgetRefresh = false
|
||||
CoreDataStack.shared.refreshWidgetData()
|
||||
}
|
||||
|
||||
var accountsCreated = 0
|
||||
var sourcesCreated = 0
|
||||
var snapshotsCreated = 0
|
||||
@@ -475,7 +484,8 @@ Personal,Real Estate,Rental Property,2024-01-01,82000,80000,Estimated value
|
||||
date: snapshot.date,
|
||||
value: snapshot.value,
|
||||
contribution: snapshot.contribution,
|
||||
notes: snapshot.notes
|
||||
notes: snapshot.notes,
|
||||
batch: true
|
||||
)
|
||||
snapshotsCreated += 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user