Fix check-ins no marcados al importar (setCompletionDate en hilo equivocado)

El import corre en un contexto de background, pero MonthlyCheckInStore muta
viewContext (main). Llamar setCompletionDate desde el background era una
violación de concurrencia de Core Data → los JournalEntry.completionTime de los
meses importados no persistían, dejando el "siguiente check-in" anclado a una
entrada vieja (p.ej. May 2025). Envuelto el marcado en viewContext.performAndWait
para ejecutarlo en la cola correcta.

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:
alexandrev-tibco
2026-07-23 18:59:36 +02:00
parent 2ea32b5494
commit 047060f126
+10 -3
View File
@@ -513,11 +513,18 @@ Personal,Real Estate,Rental Property,2024-01-01,82000,80000,Estimated value
}
if !completionDatesByMonth.isEmpty {
for (monthKey, completionDate) in completionDatesByMonth {
// MonthlyCheckInStore mutates CoreDataStack.shared.viewContext (main queue).
// applyImport runs on a BACKGROUND context, so calling setCompletionDate
// here directly was a Core Data concurrency violation the imported months'
// JournalEntry.completionTime never persisted, leaving the "next check-in"
// stuck on an old entry. Run it on the viewContext's own queue.
CoreDataStack.shared.viewContext.performAndWait {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM"
if let monthDate = formatter.date(from: monthKey) {
MonthlyCheckInStore.setCompletionDate(completionDate, for: monthDate)
for (monthKey, completionDate) in completionDatesByMonth {
if let monthDate = formatter.date(from: monthKey) {
MonthlyCheckInStore.setCompletionDate(completionDate, for: monthDate)
}
}
}
}