fix: don't update updated_at on device observations

The updated_at timestamp should only change when user metadata
changes (floor, label, position, notes), not on every scan
observation. This was breaking peer sync because observation
timestamps were overwriting metadata timestamps.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
User
2026-02-01 03:43:34 +01:00
parent 7cc7c47805
commit 7eb76498b0

View File

@@ -267,7 +267,7 @@ class DeviceDatabase:
cursor = conn.cursor()
timestamp = datetime.now().isoformat()
# Insert or update device
# Insert or update device (don't touch updated_at - that's for metadata changes only)
cursor.execute("""
INSERT INTO devices (device_id, device_type, name, ssid, manufacturer, encryption, channel, frequency, first_seen, last_seen, total_observations)
VALUES (?, 'wifi', ?, ?, ?, ?, ?, ?, ?, ?, 1)
@@ -279,8 +279,7 @@ class DeviceDatabase:
channel = COALESCE(excluded.channel, devices.channel),
frequency = COALESCE(excluded.frequency, devices.frequency),
last_seen = excluded.last_seen,
total_observations = devices.total_observations + 1,
updated_at = CURRENT_TIMESTAMP
total_observations = devices.total_observations + 1
""", (bssid, ssid, ssid, manufacturer, encryption, channel, frequency, timestamp, timestamp))
# Insert RSSI observation
@@ -326,7 +325,7 @@ class DeviceDatabase:
""", (address,))
prev = cursor.fetchone()
# Insert or update device
# Insert or update device (don't touch updated_at - that's for metadata changes only)
cursor.execute("""
INSERT INTO devices (device_id, device_type, name, manufacturer, device_class, bt_device_type, first_seen, last_seen, total_observations)
VALUES (?, 'bluetooth', ?, ?, ?, ?, ?, ?, 1)
@@ -336,8 +335,7 @@ class DeviceDatabase:
device_class = COALESCE(excluded.device_class, devices.device_class),
bt_device_type = COALESCE(excluded.bt_device_type, devices.bt_device_type),
last_seen = excluded.last_seen,
total_observations = devices.total_observations + 1,
updated_at = CURRENT_TIMESTAMP
total_observations = devices.total_observations + 1
""", (address, name, manufacturer, device_class, device_type, timestamp, timestamp))
# Insert RSSI observation