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:
@@ -102,7 +102,8 @@ class SnapshotRepository: ObservableObject {
|
||||
date: Date = Date(),
|
||||
value: Decimal,
|
||||
contribution: Decimal? = nil,
|
||||
notes: String? = nil
|
||||
notes: String? = nil,
|
||||
batch: Bool = false
|
||||
) -> Snapshot {
|
||||
let snapshot = Snapshot(context: context)
|
||||
snapshot.source = source
|
||||
@@ -113,7 +114,12 @@ class SnapshotRepository: ObservableObject {
|
||||
}
|
||||
snapshot.notes = notes
|
||||
|
||||
save()
|
||||
// In batch mode (CSV import), skip the per-row save + widget refresh — the
|
||||
// caller saves the whole context once at the end. Saving per row triggered a
|
||||
// main-thread WAL checkpoint each time → ANR on large imports.
|
||||
if !batch {
|
||||
save()
|
||||
}
|
||||
return snapshot
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user