CUB-230: hub-side deduplication for offline buffering replay
Build (Dev) / build (push) Failing after 10s
CI/CD / lint-and-typecheck (push) Successful in 6s
CI/CD / test (push) Successful in 6s
CI/CD / build (push) Failing after 8s
CI/CD / deploy (push) Has been skipped

- 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:
2026-05-23 07:40:06 +00:00
parent 1a8f67a392
commit fe193701ae
14 changed files with 25 additions and 715 deletions
+15
View File
@@ -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,