fix: miler logs read returns newest rows, not oldest (blank early-boot ping)
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WRaFH5hMRqmUQvVPQsyjZD
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user