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:
@@ -772,7 +772,14 @@ class CoreDataStack: ObservableObject {
|
||||
|
||||
// MARK: - Widget Data Refresh
|
||||
|
||||
/// When true, `refreshWidgetData()` becomes a no-op. Set during batch operations
|
||||
/// (e.g. CSV import of hundreds of snapshots) so we don't run a synchronous WAL
|
||||
/// checkpoint + widget reload per row — that hammered the main thread into an ANR.
|
||||
/// Call `refreshWidgetData()` once when the batch finishes.
|
||||
var suppressWidgetRefresh = false
|
||||
|
||||
func refreshWidgetData() {
|
||||
if suppressWidgetRefresh { return }
|
||||
if #available(iOS 14.0, *) {
|
||||
if Self.appGroupEnabled {
|
||||
checkpointWAL()
|
||||
|
||||
Reference in New Issue
Block a user