fix FK constraint: skip duplicate messages before thread reconstruction

- insertMessages checks (mailboxId, uid) existence before INSERT, returns
  only actually inserted records
- syncMailbox only runs ThreadReconstructor on newly inserted messages,
  preventing FK violations from stale UUIDs referencing ignored records
- improve error logging to show full error description

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-15 12:02:55 +01:00
parent ff91e397e8
commit 01605a01ec
3 changed files with 23 additions and 11 deletions

View File

@@ -207,10 +207,10 @@ final class MailViewModel {
try await coordinator.syncNow()
syncState = coordinator.syncState
} catch {
let desc = "\(type(of: error)): \(error.localizedDescription)"
let desc = "\(error)"
print("[MailViewModel] syncNow failed: \(desc)")
errorMessage = desc
syncState = .error(desc)
errorMessage = error.localizedDescription
syncState = .error(error.localizedDescription)
}
}