| 1 | const HISTORY_PAGE_TURNS = 60; |
| 2 | const HISTORY_JUMP_MAX_TURNS = 500; |
| 3 | const HISTORY_JUMP_MAX_ENTRIES = 1000; |
| 4 | |
| 5 | export function historyTurnsToLoad(startTurn: number, totalTurns: number, targetTurn?: number): number { |
| 6 | const normalizedTarget = Number.isInteger(targetTurn) && (targetTurn ?? 0) > 0 |
| 7 | ? Math.min(Math.max(1, totalTurns), targetTurn as number) |
| 8 | : undefined; |
| 9 | const missingTurns = normalizedTarget === undefined |
| 10 | ? HISTORY_PAGE_TURNS |
| 11 | : Math.max(HISTORY_PAGE_TURNS, startTurn - normalizedTarget); |
| 12 | return Math.min(HISTORY_JUMP_MAX_TURNS, missingTurns); |
| 13 | } |
| 14 | |
| 15 | export function historyPageRequestBudget( |
| 16 | startTurn: number, |
| 17 | totalTurns: number, |
| 18 | targetTurn?: number, |
| 19 | ): { turns: number; entries?: number } { |
| 20 | const turns = historyTurnsToLoad(startTurn, totalTurns, targetTurn); |
| 21 | return targetTurn === undefined ? { turns } : { turns, entries: HISTORY_JUMP_MAX_ENTRIES }; |
| 22 | } |
| 23 |