PEP-219: индекс events(session_id, type) — доска не перебирает все события на каждую сессию

listSessions считает переключения подписки подзапросом по events для каждой
сессии; без индекса это полный просмотр ~40 000 строк × 746 сессий (4,4 с на
копии живой базы, 0,008 с с индексом).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
peppa-bot 2026-11-18 20:57:39 +05:00
parent b47e95f91f
commit 7189fd2457
4 changed files with 4622 additions and 1 deletions

View File

@ -0,0 +1 @@
CREATE INDEX `events_session_type` ON `events` (`session_id`,`type`);

File diff suppressed because it is too large Load Diff

View File

@ -169,6 +169,13 @@
"when": 1794919319811,
"tag": "0023_curious_steel_serpent",
"breakpoints": true
},
{
"idx": 24,
"version": "6",
"when": 1795017454043,
"tag": "0024_events_session_type",
"breakpoints": true
}
]
}

View File

@ -492,7 +492,7 @@ export const events = sqliteTable(
actorClientId: text("actor_client_id"),
createdAt: createdAt(),
},
(t) => [index("events_created_at").on(t.createdAt)],
(t) => [index("events_created_at").on(t.createdAt), index("events_session_type").on(t.sessionId, t.type)],
);
/** Small key/value store for service state (Telegram offset, pairing, binding). */