Admin logs list no longer joins prompt/completion content for every row — content is fetched per-row only when a log is expanded in the dashboard, since a table of chat-length blobs was slow to serialize even at low row counts. request_logs.user_id (previously unpopulated despite an index existing on it) is now set from the owning key on every insert, including synthetic dashboard keys, and log queries filter on it directly instead of a virtual_keys subquery. Pagination switches from OFFSET to a (created_at, id) keyset cursor so paging deep into the log stays cheap. Adds indexes on provider_name/key_prefix used by the admin filters.
14 lines
630 B
SQL
14 lines
630 B
SQL
-- Backfill user_id on existing rows so the direct column (already indexed
|
|
-- via idx_request_logs_user) matches historical logs written before the app
|
|
-- started populating it from the owning key.
|
|
UPDATE request_logs rl
|
|
SET user_id = vk.user_id
|
|
FROM virtual_keys vk
|
|
WHERE rl.virtual_key_id = vk.id
|
|
AND rl.user_id IS NULL;
|
|
|
|
-- Support the admin logs list's provider/key filters without a full scan
|
|
-- once the table grows past a handful of rows.
|
|
CREATE INDEX idx_request_logs_provider_name ON request_logs (provider_name, created_at DESC);
|
|
CREATE INDEX idx_request_logs_key_prefix ON request_logs (key_prefix, created_at DESC);
|