codeburn/app/renderer/lib/streak.ts
Resham Joshi 3e9542d63d
Consistent period totals and incremental refresh (#1467)
Every period headline now comes from one aggregation, so switching period no longer mixes snapshots taken minutes apart and Lifetime can no longer read below the six months inside it.
Days preserved from expired transcripts count toward the totals, and the usage streak is one machine-wide number taken from the hydrated daily cache.
A provider-filtered hero reads the scoped payload instead of the unscoped one.
Anchored menus and popovers render through a portal, so the card anatomy no longer clips them after three rows.
The Spend by-branch picker groups checkouts by git origin, one entry per repository with the checkout count beside it.
On the performance side, serve invalidation is scoped to the day a changed file can hold, -shm writes are ignored, and the optimize detectors keep one range-independent scan record with ordered version events.
Memo budgets are set by retained bytes, and every serve response carries the generation and timestamp it was built from.
A 30D stay with appends drops from 7253ms to 2387ms and peak RSS from 2904MB to 1819MB.
No cache format changed. Payloads stay byte-identical except for periodTotals, streak and liveSessions.
2026-09-17 12:35:05 +02:00

20 lines
785 B
TypeScript

/**
* The machine's usage streak, as last reported by the CLI.
*
* The CLI emits it only on the all-provider path, because counting active days
* under a provider filter would mean scanning providers the view does not show.
* Every screen therefore quotes the last value the app was given rather than
* deriving its own from a period-narrowed history, which is what made the same
* pill read a different number on every tab.
*/
let lastStreak: number | null = null
export function rememberStreak(reported: number | undefined): number | null {
if (typeof reported === 'number' && Number.isFinite(reported)) lastStreak = reported
return lastStreak
}
/** Test-only: drop the remembered value between renders. */
export function __resetStreak(): void {
lastStreak = null
}