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