From 6e5da0932977010f43844eb2b821b3836af73e5e Mon Sep 17 00:00:00 2001 From: Suriyakumarvijayanayagam Date: Fri, 28 Aug 2026 16:43:29 +0530 Subject: [PATCH] fix: miler logs read returns newest rows, not oldest (blank early-boot ping) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GetMilerLogs fetched miler_periodic_logs with ZRangeByScore (ascending) + Count: limit, so ?limit=1 returned the FIRST ping of the day — an early-boot row with GPS but empty battery/connection/accuracy — instead of the latest fix. That is exactly the blank-telemetry the rider-detail console showed, even though the app was sending full telemetry (verified in live Redis). Switch to ZRevRangeByScore (newest-first) so a limit-capped window keeps the most recent rows, then flip the slice back to chronological so the trail and distance sum still walk consecutive fixes in ride order. ?limit=1 now returns the latest full-telemetry row. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01WRaFH5hMRqmUQvVPQsyjZD --- controllers/adminMilerOpsController.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/controllers/adminMilerOpsController.go b/controllers/adminMilerOpsController.go index 9b30bf3..6405c10 100644 --- a/controllers/adminMilerOpsController.go +++ b/controllers/adminMilerOpsController.go @@ -294,8 +294,13 @@ func GetMilerLogs(c *fiber.Ctx) error { } // The zset is scored by the log's own unix timestamp, so the range query is - // the date filter — no scanning every key for the rider. - keys, err := db.Rdb.ZRangeByScore(db.Ctx, fmt.Sprintf("miler_periodic_logs:%d", profile.Userid), &redis.ZRangeBy{ + // the date filter — no scanning every key for the rider. Fetch newest-first + // (ZRevRangeByScore) so that when the window is capped by limit we keep the + // most recent rows, not the oldest: a rider-detail card asking ?limit=1 wants + // the latest fix (full battery/speed/connection telemetry), and the first + // ping of the day is an early-boot row whose fields are still blank. The + // slice is flipped back to chronological order below for the trail/distance. + keys, err := db.Rdb.ZRevRangeByScore(db.Ctx, fmt.Sprintf("miler_periodic_logs:%d", profile.Userid), &redis.ZRangeBy{ Min: strconv.FormatInt(from.Unix(), 10), Max: strconv.FormatInt(to.Unix(), 10), Count: int64(limit), @@ -327,6 +332,13 @@ func GetMilerLogs(c *fiber.Ctx) error { } } + // Flip the newest-first fetch back to chronological (oldest→newest) so the + // returned trail reads in ride order and the distance sum below walks + // consecutive fixes. The latest fix is still included — it's just last now. + for i, j := 0, len(logs)-1; i < j; i, j = i+1, j-1 { + logs[i], logs[j] = logs[j], logs[i] + } + // Trail distance, so the console can show kms actually ridden over the // window rather than only the per-booking figure. var distance float64