fix(lap): keep best laps per track layout and count the current session for records

A layout switch during a running open practice kept every driver's
old-layout best lap, blocking personal-best calls and skewing the
practice leaderboard. Best laps now restart on a new layout and each
lap records its layout. The track record baseline now includes the
current session so the same record isn't called twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
larssandandClaude Opus 5.5 committed 2026-10-03 21:14:19 +02:00
1 parent ebd0f74f40
commit 8b63dd2372
12 files changed
+125 -8

No files matched your search

+9 -1
View File
@@ -5046,9 +5046,17 @@ function addTrackLayout(label, startedAtMs = Date.now()) {
state.trackLayouts = normalizeTrackLayouts(layouts, { uid });
// A practice session that keeps running across the switch moves onto the new layout;
// its earlier laps stay on the old one because training laps are tagged per lap.
// Its best laps start over too: personal bests, session fastest and the leaderboard's best
// lap are per layout, so the old layout's times can't block or fake a new best.
if (startedAtMs <= Date.now()) {
state.sessions.forEach((session) => {
if (isPracticeSessionType(session.type) && ["running", "paused"].includes(session.status)) session.trackLayoutId = layout.id;
if (!isPracticeSessionType(session.type) || !["running", "paused"].includes(session.status)) return;
session.trackLayoutId = layout.id;
Object.values(state.resultsBySession?.[session.id]?.competitors || {}).forEach((entry) => {
entry.bestLapMs = null;
entry.bestLapLayoutId = layout.id;
delete lastOverlayBestLapByKey[`${session.id}:${entry.key}`];
});
});
}
saveState();