2.4.2 #8
@@ -220,14 +220,23 @@ final class BackupService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let localUpdatedAt = settings.favoriteModelsUpdatedAt
|
let localUpdatedAt = settings.favoriteModelsUpdatedAt
|
||||||
|
let localIds = settings.favoriteModelIds
|
||||||
if remote.updatedAt > localUpdatedAt {
|
if remote.updatedAt > localUpdatedAt {
|
||||||
settings.favoriteModelIds = Set(remote.ids)
|
settings.favoriteModelIds = Set(remote.ids)
|
||||||
settings.favoriteModelsUpdatedAt = remote.updatedAt
|
settings.favoriteModelsUpdatedAt = remote.updatedAt
|
||||||
log.info("Applied \(remote.ids.count) favorite model(s) from iCloud (remote was newer)")
|
log.info("Applied \(remote.ids.count) favorite model(s) from iCloud (remote was newer)")
|
||||||
} else if localUpdatedAt > remote.updatedAt {
|
} else if localUpdatedAt > remote.updatedAt {
|
||||||
await pushFavorites()
|
await pushFavorites()
|
||||||
|
} else if Set(remote.ids) != localIds {
|
||||||
|
// Tied timestamps (both empty is the common case: two machines that already had
|
||||||
|
// favorites before this sync feature existed, neither ever bumped the timestamp).
|
||||||
|
// Union rather than silently dropping one side's favorites.
|
||||||
|
settings.favoriteModelIds = localIds.union(remote.ids)
|
||||||
|
settings.favoriteModelsUpdatedAt = ISO8601DateFormatter().string(from: Date())
|
||||||
|
await pushFavorites()
|
||||||
|
log.info("Merged favorites from iCloud (tied timestamps) — union of \(localIds.count) local + \(remote.ids.count) remote")
|
||||||
}
|
}
|
||||||
// Equal timestamps: already in sync, nothing to do.
|
// Equal timestamps and identical sets: already in sync, nothing to do.
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Automatic Backup
|
// MARK: - Automatic Backup
|
||||||
|
|||||||
Reference in New Issue
Block a user