From abdf7d39257bced6d82eeea5a0f8fb9f8a837b6d Mon Sep 17 00:00:00 2001 From: Richard Zink Date: Sat, 21 Nov 2026 22:51:06 +0100 Subject: [PATCH] Index usage(session_id): the Factory overview scanned the usage table 900 times per request Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 6 ++++++ server/src/store.rs | 1 + web/src/whatsnew.ts | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2f9896..ceff40a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to CodeCraft. Versions follow [Semantic Versioning](https://semver.org/); until 1.0, minor versions may contain breaking changes. +## [Unreleased] + +### Fixed + +- **Factory page made the server stall (HTTP 504, one CPU core at 100 %).** The overview sums tokens and cost of up to 300 runs per request from the `usage` table, which had no index on `session_id`: every request scanned the table 900 times (about 4 s while holding the database lock). The index `usage_session` makes it take milliseconds (measured on the production database: 4.0 s → 8 ms). + ## [v202611-00079] – 2026-11-21 ### Changed diff --git a/server/src/store.rs b/server/src/store.rs index 3b40771..96cd7ce 100644 --- a/server/src/store.rs +++ b/server/src/store.rs @@ -51,6 +51,7 @@ impl Store { ); CREATE INDEX IF NOT EXISTS usage_ts ON usage(ts); CREATE INDEX IF NOT EXISTS usage_root ON usage(root_session_id); + CREATE INDEX IF NOT EXISTS usage_session ON usage(session_id); CREATE TABLE IF NOT EXISTS users ( id TEXT PRIMARY KEY, username TEXT NOT NULL UNIQUE COLLATE NOCASE, diff --git a/web/src/whatsnew.ts b/web/src/whatsnew.ts index e960dbe..0d290e4 100644 --- a/web/src/whatsnew.ts +++ b/web/src/whatsnew.ts @@ -3,6 +3,10 @@ * under "unreleased"; scripts/release.sh renames the key to the release version. */ export const WHATS_NEW: Record = { + unreleased: { + en: ["Fixed: the Factory page no longer makes the server stall (504 errors, high CPU)"], + de: ["Behoben: die Factory-Seite lässt den Server nicht mehr hängen (504-Fehler, hohe CPU-Last)"], + }, "202611-00079": { en: ["The server binary keeps its symbols (for diagnosing a high CPU load); no change in behaviour"], de: ["Das Server-Binary behält seine Symbole (zur Diagnose einer hohen CPU-Last); keine Änderung im Verhalten"],