From 44a43e59868c8c103e410e946eb7fd66e63c02cd Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Fri, 4 Dec 2026 07:26:17 +0100 Subject: [PATCH] perf: bound the trigger and token filters links open (#12847) Co-authored-by: Claude Opus 5.5 --- frontend/src/lib/components/RunsPage.svelte | 4 +++- .../auditLogs/AuditLogDetails.svelte | 9 +++++---- .../auditLogs/AuditLogsTable.svelte | 9 ++++++++- .../lib/components/auditLogs/tokenWindow.ts | 12 ++++++++++++ .../components/runs/JobDetailFieldConfig.ts | 9 ++++++++- .../components/triggers/TriggerList.svelte | 10 ++++++---- .../triggers/native/NativeTriggerTable.svelte | 11 ++++++----- .../(root)/(logged)/audit_logs/+page.svelte | 19 ++++++++++++++++--- 8 files changed, 64 insertions(+), 19 deletions(-) create mode 100644 frontend/src/lib/components/auditLogs/tokenWindow.ts diff --git a/frontend/src/lib/components/RunsPage.svelte b/frontend/src/lib/components/RunsPage.svelte index 4ccf17ca69..4822a27fa4 100644 --- a/frontend/src/lib/components/RunsPage.svelte +++ b/frontend/src/lib/components/RunsPage.svelte @@ -362,10 +362,12 @@ const filterBySchedule = resetAndFilterBy((s) => (filters.val.schedule_path = s)) const filterByWorker = resetAndFilterBy((s) => (filters.val.worker = s)) const filterByTriggerKind = resetAndFilterBy((s) => (filters.val.job_trigger_kind = s)) - // Two kinds can share a path, so the kind narrows it. + // Two kinds can share a path, so the kind narrows it. The runnable's path is what lets the + // query use an index: `trigger` has none, so a rarely fired trigger would scan every job. const filterByTriggerPath = resetAndFilterBy((job: Job) => { filters.val.trigger_path = job.trigger_path ?? undefined filters.val.job_trigger_kind = job.trigger_kind ?? undefined + filters.val.path = job.script_path ?? undefined }) function typeOfChart(s: string | null): 'RunChart' | 'ConcurrencyChart' { diff --git a/frontend/src/lib/components/auditLogs/AuditLogDetails.svelte b/frontend/src/lib/components/auditLogs/AuditLogDetails.svelte index 5afbe60c12..0c6e462755 100644 --- a/frontend/src/lib/components/auditLogs/AuditLogDetails.svelte +++ b/frontend/src/lib/components/auditLogs/AuditLogDetails.svelte @@ -12,8 +12,9 @@ logs: AuditLog[] selectedId?: number | undefined onClose?: () => void - /** Filter the list down to the entries made with this token prefix. */ - onFilterToken?: (prefix: string) => void + /** Filter the list down to the entries made with this token prefix, around `at`, the + * entry's timestamp. */ + onFilterToken?: (prefix: string, at: string) => void } let { logs, selectedId = undefined, onClose, onFilterToken }: Props = $props() @@ -79,8 +80,8 @@ unifiedSize="sm" iconOnly startIcon={{ icon: ListFilterPlus }} - title="Show every entry made with this token" - onClick={() => onFilterToken(log.span!)} + title="Show the entries made with this token around this one" + onClick={() => onFilterToken(log.span!, log.timestamp)} /> {/if} diff --git a/frontend/src/lib/components/auditLogs/AuditLogsTable.svelte b/frontend/src/lib/components/auditLogs/AuditLogsTable.svelte index 8b37e10993..4e1d2cf48f 100644 --- a/frontend/src/lib/components/auditLogs/AuditLogsTable.svelte +++ b/frontend/src/lib/components/auditLogs/AuditLogsTable.svelte @@ -29,6 +29,8 @@ onBatchSizeChange?: (batchSize: number) => void onStopLoading?: () => void onselect?: (id: number) => void + /** `at` is the entry's timestamp, which the filter's time window is set around. */ + onFilterToken?: (prefix: string, at: string) => void } let { @@ -47,6 +49,7 @@ onBatchSizeChange, onStopLoading, onselect, + onFilterToken, loading, loadingExtra = false, onLoadMore @@ -261,7 +264,11 @@ iconOnly startIcon={{ icon: ListFilterPlus }} on:click={() => { - tokenFilter = token + if (onFilterToken) { + onFilterToken(token, logOrDate.log.timestamp) + } else { + tokenFilter = token + } }} /> diff --git a/frontend/src/lib/components/auditLogs/tokenWindow.ts b/frontend/src/lib/components/auditLogs/tokenWindow.ts new file mode 100644 index 0000000000..9758bbb01e --- /dev/null +++ b/frontend/src/lib/components/auditLogs/tokenWindow.ts @@ -0,0 +1,12 @@ +// No index covers an audit entry's token, so a token filter reads every entry of the workspace in +// its time range. Measured on a busy cloud workspace: about 0.7s over two days, over 20s past a +// week. Anything that opens the audit logs on a token keeps it to this window around a moment. +const TOKEN_WINDOW_MS = 24 * 60 * 60 * 1000 + +export function tokenWindow(at: string | number | Date): { after: string; before: string } { + const t = new Date(at).getTime() + return { + after: new Date(t - TOKEN_WINDOW_MS).toISOString(), + before: new Date(t + TOKEN_WINDOW_MS).toISOString() + } +} diff --git a/frontend/src/lib/components/runs/JobDetailFieldConfig.ts b/frontend/src/lib/components/runs/JobDetailFieldConfig.ts index 21c17afad9..9d775604fb 100644 --- a/frontend/src/lib/components/runs/JobDetailFieldConfig.ts +++ b/frontend/src/lib/components/runs/JobDetailFieldConfig.ts @@ -11,9 +11,16 @@ import { type PageItemRef, type TriggerKind } from '$lib/components/sessions/previewPaths' +import { tokenWindow } from '$lib/components/auditLogs/tokenWindow' import { Calendar, Bot } from 'lucide-svelte' import BarsStaggered from '$lib/components/icons/BarsStaggered.svelte' +function tokenWindowParams(createdAt: string | undefined): string { + if (!createdAt) return '' + const { after, before } = tokenWindow(createdAt) + return `&after=${encodeURIComponent(after)}&before=${encodeURIComponent(before)}` +} + /** * Categories of job types for field configuration */ @@ -247,7 +254,7 @@ export const fieldConfigs: Record = { }, getHref: (job, workspaceId) => job.token_prefix - ? `${AUDIT_LOGS_PATH}?token=${encodeURIComponent(job.token_prefix)}&workspace=${encodeURIComponent(job.workspace_id || workspaceId)}` + ? `${AUDIT_LOGS_PATH}?token=${encodeURIComponent(job.token_prefix)}&workspace=${encodeURIComponent(job.workspace_id || workspaceId)}${tokenWindowParams(job.created_at)}` : null }, diff --git a/frontend/src/lib/components/triggers/TriggerList.svelte b/frontend/src/lib/components/triggers/TriggerList.svelte index 1de6d5c638..83ae60b322 100644 --- a/frontend/src/lib/components/triggers/TriggerList.svelte +++ b/frontend/src/lib/components/triggers/TriggerList.svelte @@ -99,8 +99,10 @@ const config = $derived(TRIGGER_LIST_CONFIG[triggerKind]) // The row's buttons show from md up; their menu entries are there for narrower screens. const wide = new MediaQuery('min-width: 768px') - const runsHref = (path: string) => - `/runs?trigger_path=${encodeURIComponent(path)}&job_trigger_kind=${triggerKind}` + // The runnable's path is what lets the runs query use an index: `trigger` has none, so a + // trigger with no runs would otherwise scan every job of the workspace. + const runsHref = (path: string, runnablePath: string) => + `/runs?trigger_path=${encodeURIComponent(path)}&job_trigger_kind=${triggerKind}&path=${encodeURIComponent(runnablePath)}` const isAdmin = $derived( !!(operatingUser.current?.is_admin || operatingUser.current?.is_super_admin) ) @@ -809,7 +811,7 @@
@@ -301,6 +313,7 @@ bind:usernameFilter={username} bind:resourceFilter={resource} bind:tokenFilter={tokenPrefix} + onFilterToken={filterByToken} {batchProgress} batchSize={auditLogsLoader.currentBatchSize} onBatchSizeChange={(size) => auditLogsLoader.restreamWithBatchSize(size)} @@ -322,8 +335,8 @@ { - tokenPrefix = prefix + onFilterToken={(prefix, at) => { + filterByToken(prefix, at) auditLogDrawer?.closeDrawer() }} />