#3978·crush

crush stats time series come out in random order

Author: vitolee-1018Created Sep 28, 2026Updated Sep 28, 2026

What happened

mergeStats fills UsageByDay, UsageByHour, UsageByDayOfWeek, RecentActivity, and HourDayHeatmap by ranging over maps. Map iteration order is random.

UsageByModel and ToolUsage are already sorted by count. The time series are not, so the same data can be listed in a different order on every run.

Expected

UsageByDay is newest first. The daily table keeps only the first 30 rows (usage_by_day.slice(0, 30)), and GetUsageByDay is already ORDER BY day DESC. Ascending order would show the oldest 30 days.

Recent activity stays oldest-first, matching GetRecentActivity (ORDER BY day ASC) and the activity chart. Hours, weekdays, and the heatmap stay in ascending key order.

Tests

TestMergeStatsOrdersTimeSeries failed before the sorts. One failure was 2026-01-08 appearing before 2026-01-04. After the sorts, UsageByDay is newest first and the other series stay in ascending key order.