fix: preserve cached events when a calendar has a per-source sync error
Root cause: mergeIntoCache() unconditionally evicted every event in the fetched date range, even for calendars whose sync failed. Those calendars' events were removed and never restored, so the calendar appeared to vanish. Fix: - SyncError now decodes calendarId from the server's "calendar_id" field (added server-side in e0ea16f but not yet read by iOS). - mergeIntoCache() gains a keepKeysInRange parameter: events from failed calendars are retained (not evicted) even within the fetch window. - loadEvents() and prefetchBackground() compute the failed keys from the syncErrors list and pass them to mergeIntoCache. Result: when CalDAV / Google / HA sync fails for a specific calendar, the user sees stale-but-correct events alongside the existing error banner, instead of a completely empty calendar with no explanation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -25,16 +25,18 @@ struct EventPerson: Hashable {
|
||||
/// succeeded, just not every source within it.
|
||||
struct SyncError: Hashable {
|
||||
let source: String
|
||||
let calendarId: String? // nil on older server responses without calendar_id
|
||||
let name: String
|
||||
let message: String
|
||||
|
||||
static func from(json: [String: Any]) -> SyncError? {
|
||||
guard
|
||||
let source = json["source"] as? String,
|
||||
let name = json["name"] as? String,
|
||||
let source = json["source"] as? String,
|
||||
let name = json["name"] as? String,
|
||||
let message = json["message"] as? String
|
||||
else { return nil }
|
||||
return SyncError(source: source, name: name, message: message)
|
||||
let calendarId = json["calendar_id"].map { "\($0)" }
|
||||
return SyncError(source: source, calendarId: calendarId, name: name, message: message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user