diff --git a/internal/sessions/stats.go b/internal/sessions/stats.go index 96205da2c..8cb9ed5d1 100644 --- a/internal/sessions/stats.go +++ b/internal/sessions/stats.go @@ -382,6 +382,9 @@ func statsRead(days int, now time.Time, native map[string]bool) Stats { groups := byKey(files, func(f *file) bool { return shares[f.key] != nil }) first, _ := time.ParseInLocation(time.DateOnly, out.From, time.Local) + // made to size: grown by append, 34k sessions' list held a quarter + // more than its rows, and every copy it was grown through (#2278) + out.Sessions = make([]Summary, 0, len(shares)) for key, sh := range shares { if len(sh.dates) == 0 { continue @@ -441,6 +444,7 @@ func statsRead(days int, now time.Time, native map[string]bool) Stats { return a.Key < b.Key }) // keys after the sort, so they name the sessions in the order they are in + out.Keys = make([]string, 0, len(out.Sessions)) for _, s := range out.Sessions { out.Keys = append(out.Keys, s.Key) } diff --git a/internal/sessions/stats_test.go b/internal/sessions/stats_test.go index f7ea04149..44b8ade13 100644 --- a/internal/sessions/stats_test.go +++ b/internal/sessions/stats_test.go @@ -237,6 +237,10 @@ func TestStatsHoursAndSessions(t *testing.T) { if !sortedByLast(s.Sessions) || len(s.Sessions) < 3 { t.Fatalf("sessions %+v", s.Sessions) } + // each range keeps its list, so it holds its rows and no more (#2278) + if cap(s.Sessions) != len(s.Sessions) || cap(s.Keys) != len(s.Keys) { + t.Fatalf("%d sessions held in %d, %d keys in %d", len(s.Sessions), cap(s.Sessions), len(s.Keys), cap(s.Keys)) + } // a range counts only its own days day := statsAt(1, time.Date(2026, 9, 21, 12, 0, 0, 0, time.UTC)) if x := find(day); x == nil || x.Tokens != (Tokens{400, 40, 10, 0, 0}) || x.Active != 240 || len(x.Days) != 1 || x.Days[0] != 0 {