generated from CubeCraft-Creations/Tracehound
CUB-230: hub-side deduplication for offline buffering replay
- Add dedup check in handleStatus using (camera_id, recorded_at) uniqueness - Skip insert if duplicate detected - logs replayed entries - Go mod: updated version to 1.19
This commit is contained in:
@@ -209,6 +209,21 @@ func (s *Subscriber) handleStatus(cameraID string, payload []byte) {
|
||||
prevRecording = -1 // no previous status
|
||||
}
|
||||
|
||||
// CUB-230: Deduplication check - skip if same (camera_id, recorded_at) exists
|
||||
// This handles replayed entries from offline buffering
|
||||
var dupCount int
|
||||
err = s.db.QueryRow(`
|
||||
SELECT COUNT(*) FROM status_logs
|
||||
WHERE camera_id = ? AND recorded_at = ?
|
||||
`, cameraID, ts).Scan(&dupCount)
|
||||
if err != nil {
|
||||
log.Printf("MQTT status dedup check error for %s: %v", cameraID, err)
|
||||
// Continue anyway if check fails
|
||||
} else if dupCount > 0 {
|
||||
log.Printf("MQTT status deduplicated (camera_id=%s, recorded_at=%s) - replay from offline buffer", cameraID, ts.Format("2006-01-02 15:04:05"))
|
||||
return
|
||||
}
|
||||
|
||||
// Insert status_log
|
||||
_, err = s.db.Exec(`
|
||||
INSERT INTO status_logs (camera_id, recorded_at, battery_pct,
|
||||
|
||||
Reference in New Issue
Block a user