perf(schema): index LiteLLM_SpendLogs by session for the session view

Add (session_id, api_key, startTime DESC, request_id) so checking whether a
spend log row is the newest row of its session is one index probe. The
migration builds it CONCURRENTLY so spend log inserts keep flowing during a
rolling deploy.
This commit is contained in:
shrey-berri 2026-09-26 17:59:43 +00:00
parent 3b715525d3
commit 04d4a19c9d
No known key found for this signature in database
4 changed files with 5 additions and 0 deletions

View file

@ -0,0 +1,2 @@
-- CreateIndex (CONCURRENTLY): keep this a single statement so Prisma Migrate applies it outside a transaction
CREATE INDEX CONCURRENTLY IF NOT EXISTS "LiteLLM_SpendLogs_session_id_api_key_startTime_request_id_idx" ON "LiteLLM_SpendLogs"("session_id", "api_key", "startTime" DESC, "request_id");

View file

@ -684,6 +684,7 @@ model LiteLLM_SpendLogs {
@@index([session_id])
@@index([litellm_call_id])
@@index([api_key, startTime])
@@index([session_id, api_key, startTime(sort: Desc), request_id])
}
model LiteLLM_BudgetWindowSpend {

View file

@ -684,6 +684,7 @@ model LiteLLM_SpendLogs {
@@index([session_id])
@@index([litellm_call_id])
@@index([api_key, startTime])
@@index([session_id, api_key, startTime(sort: Desc), request_id])
}
model LiteLLM_BudgetWindowSpend {

View file

@ -684,6 +684,7 @@ model LiteLLM_SpendLogs {
@@index([session_id])
@@index([litellm_call_id])
@@index([api_key, startTime])
@@index([session_id, api_key, startTime(sort: Desc), request_id])
}
model LiteLLM_BudgetWindowSpend {