perf(usage): bound lastUsed overlay scan to 2-day window; reach max thinking tier

getUsageStats("all") shipped the entire usageHistory table to JS just to
refine lastUsed (~2s on 290K rows, on every statsEmitter update per SSE
listener). Bound the overlay to a 2-day indexed range scan; older entries
keep day-level lastUsed from usageDaily aggregates. Totals unaffected.

budgetToLevel now maps budgets > 80384 (midpoint of 32768/128000) to
"max" instead of clamping to "xhigh", so the top reasoning tier is
reachable from large budget_tokens requests.
This commit is contained in:
Rafli Ahmad Zulfikar
2026-09-22 15:06:03 +07:00
committed by decolua
parent ce9ac43da5
commit d1de324586
3 changed files with 52 additions and 3 deletions

View File

@@ -34,6 +34,8 @@ export function effortToThinkingLevel(effort) {
// Numeric budget → nearest discrete level (reverse map via thresholds).
// Returns null when budget <= 0 (no reasoning).
// Thresholds are midpoints between LEVEL_TO_BUDGET values: max (128000) is
// reachable, with the xhigh/max boundary at the 32768/128000 midpoint (80384).
export function budgetToLevel(budget) {
const b = Number(budget);
if (!b || b <= 0) return null;
@@ -41,7 +43,8 @@ export function budgetToLevel(budget) {
if (b <= 4096) return "low";
if (b <= 16384) return "medium";
if (b <= 28672) return "high";
return "xhigh";
if (b <= 80384) return "xhigh";
return "max";
}
// Gemini thinkingBudget (numeric) → OpenAI reasoning_effort (antigravity reverse map).