## Problem BT advertisements arrive every 1-2 seconds → recordDiscovery() called → CloudKit save → conflict with other device → endless ping-pong Old throttling: 15 seconds (too aggressive for CloudKit replication) ## Solution Increase throttling from 15s → 120s (2 minutes) Each device now persists discovery updates to CloudKit max once every 2 minutes per meter, instead of every 15 seconds. ## Result - Local lastSeen still updates every 1-2s (for BT tracking) - CloudKit saves only once per 2 minutes (prevents conflicts) - Reduces sync traffic by 8x (120s vs 15s) - Multiple devices can coexist without constant conflicts ## Code Change AppData.swift:555 - Old: `now.timeIntervalSince(previousSeenAt) < 15` - New: `now.timeIntervalSince(previousSeenAt) < 120` ✅ Build: Mac Catalyst SUCCESS Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@@ -549,10 +549,12 @@ private final class CloudDeviceSettingsStore {
|
||
| 549 | 549 |
context.delete(duplicate) |
| 550 | 550 |
} |
| 551 | 551 |
let now = Date() |
| 552 |
+ // Throttle CloudKit updates: only persist discovery once per 2 minutes per device |
|
| 553 |
+ // to avoid constant conflicts between devices on frequent BT advertisements |
|
| 552 | 554 |
if let previousSeenAt = object.value(forKey: "lastSeenAt") as? Date, |
| 553 | 555 |
let previousSeenBy = object.value(forKey: "lastSeenByDeviceID") as? String, |
| 554 | 556 |
previousSeenBy == seenByDeviceID, |
| 555 |
- now.timeIntervalSince(previousSeenAt) < 15 {
|
|
| 557 |
+ now.timeIntervalSince(previousSeenAt) < 120 {
|
|
| 556 | 558 |
return |
| 557 | 559 |
} |
| 558 | 560 |
object.setValue(macAddress, forKey: "macAddress") |