From 9f908aed9e97d6e5900b33526088404db1f15126 Mon Sep 17 00:00:00 2001 From: Erik Date: Wed, 15 Jul 2026 19:12:40 +0200 Subject: [PATCH] fix(inventory-go): backfill-od clears stale od_rating for non-matching weapons Co-Authored-By: Claude Fable 5 --- go-services/inventory-go/ingest.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/go-services/inventory-go/ingest.go b/go-services/inventory-go/ingest.go index 213c60cc..1a6558ea 100644 --- a/go-services/inventory-go/ingest.go +++ b/go-services/inventory-go/ingest.go @@ -259,10 +259,10 @@ func (s *Server) handleBackfillOD(w http.ResponseWriter, r *http.Request) { } type upd struct { id int - od float64 + od *float64 // nil → clear stale OD (weapon no longer matches any rule) } var updates []upd - scanned := 0 + scanned, rated := 0, 0 for rows.Next() { var id int var oj map[string]any @@ -273,7 +273,13 @@ func (s *Server) handleBackfillOD(w http.ResponseWriter, r *http.Request) { } scanned++ if od, ok := computeOD(oj); ok { - updates = append(updates, upd{id, od}) + v := od + updates = append(updates, upd{id, &v}) + rated++ + } else { + // No matching rule → ensure od_rating is NULL (clears any stale value + // from a prior formula so the column never keeps a wrong number). + updates = append(updates, upd{id, nil}) } } rows.Close() @@ -285,7 +291,7 @@ func (s *Server) handleBackfillOD(w http.ResponseWriter, r *http.Request) { } updated++ } - writeJSON(w, http.StatusOK, map[string]any{"scanned": scanned, "updated": updated}) + writeJSON(w, http.StatusOK, map[string]any{"scanned": scanned, "rated": rated, "updated": updated}) } func parseNaiveTime(s string) time.Time {