mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-12-04 08:09:16 +00:00
perf: bound the trigger and token filters links open (#12847)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a3cd31addd
commit
44a43e5986
@@ -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' {
|
||||
|
||||
@@ -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}
|
||||
</div>
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
@@ -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<JobField, FieldConfig> = {
|
||||
},
|
||||
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
|
||||
},
|
||||
|
||||
|
||||
@@ -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 @@
|
||||
|
||||
<div class="flex gap-2 items-center justify-end shrink-0">
|
||||
<Button
|
||||
href={runsHref(path)}
|
||||
href={runsHref(path, script_path)}
|
||||
disabled={draft_only}
|
||||
unifiedSize="md"
|
||||
startIcon={{ icon: List }}
|
||||
@@ -877,7 +879,7 @@
|
||||
icon: List,
|
||||
disabled: draft_only,
|
||||
hide: wide.current,
|
||||
href: runsHref(path)
|
||||
href: runsHref(path, script_path)
|
||||
},
|
||||
...(isDeployable('trigger', path, deployUiSettings)
|
||||
? [
|
||||
|
||||
@@ -40,9 +40,10 @@
|
||||
const serviceConfig = $derived(getServiceConfig(service))
|
||||
// The row's buttons show from md up; their menu entries are there for narrower screens.
|
||||
const wide = new MediaQuery('min-width: 768px')
|
||||
// A native trigger's runs record its external id as their trigger.
|
||||
const runsHref = (externalId: string) =>
|
||||
`/runs?trigger_path=${encodeURIComponent(externalId)}&job_trigger_kind=${service}`
|
||||
// A native trigger's runs record its external id as their trigger. The runnable's path is
|
||||
// what lets the runs query use an index: `trigger` has none.
|
||||
const runsHref = (externalId: string, runnablePath: string) =>
|
||||
`/runs?trigger_path=${encodeURIComponent(externalId)}&job_trigger_kind=${service}&path=${encodeURIComponent(runnablePath)}`
|
||||
let deleteConfirmationOpen = $state(false)
|
||||
let triggerToDelete = $state<ExtendedNativeTrigger | null>(null)
|
||||
let isDeleting = $state(false)
|
||||
@@ -181,7 +182,7 @@
|
||||
hideDropdown
|
||||
/>
|
||||
<Button
|
||||
href={runsHref(trigger.external_id)}
|
||||
href={runsHref(trigger.external_id, trigger.script_path)}
|
||||
unifiedSize="md"
|
||||
startIcon={{ icon: List }}
|
||||
variant="subtle"
|
||||
@@ -216,7 +217,7 @@
|
||||
displayName: 'View runs',
|
||||
icon: List,
|
||||
hide: wide.current,
|
||||
href: runsHref(trigger.external_id)
|
||||
href: runsHref(trigger.external_id, trigger.script_path)
|
||||
},
|
||||
{
|
||||
displayName: 'Delete',
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import { Splitpanes, Pane } from 'svelte-splitpanes'
|
||||
import AuditLogsTimeline from '$lib/components/auditLogs/AuditLogsTimeline.svelte'
|
||||
import { useAuditLogsLoader } from '$lib/components/auditLogs/useAuditLogsLoader.svelte'
|
||||
import { tokenWindow } from '$lib/components/auditLogs/tokenWindow'
|
||||
import { isUuid } from '$lib/utils/uuid'
|
||||
|
||||
let username: string = $state(page.url.searchParams.get('username') ?? 'all')
|
||||
@@ -29,6 +30,16 @@
|
||||
let resource: string | undefined = $state(page.url.searchParams.get('resource') ?? undefined)
|
||||
let jobId: string | undefined = $state(page.url.searchParams.get('job_id') ?? undefined)
|
||||
let tokenPrefix: string | undefined = $state(page.url.searchParams.get('token') ?? undefined)
|
||||
|
||||
// A timeframe the user already picked is kept.
|
||||
function filterByToken(prefix: string, at: string) {
|
||||
tokenPrefix = prefix
|
||||
if (!after && !before) {
|
||||
const window = tokenWindow(at)
|
||||
after = window.after
|
||||
before = window.before
|
||||
}
|
||||
}
|
||||
let scope: undefined | 'all_workspaces' | 'instance' = $state(
|
||||
(page.url.searchParams.get('scope') ?? undefined) as undefined | 'all_workspaces' | 'instance'
|
||||
)
|
||||
@@ -246,6 +257,7 @@
|
||||
bind:usernameFilter={username}
|
||||
bind:resourceFilter={resource}
|
||||
bind:tokenFilter={tokenPrefix}
|
||||
onFilterToken={filterByToken}
|
||||
hasMore={auditLogsLoader.hasMore}
|
||||
loadingExtra={auditLogsLoader.loadingExtra}
|
||||
onLoadMore={() => auditLogsLoader.loadMore()}
|
||||
@@ -278,7 +290,7 @@
|
||||
onClose={() => {
|
||||
selectedId = undefined
|
||||
}}
|
||||
onFilterToken={(prefix) => (tokenPrefix = prefix)}
|
||||
onFilterToken={filterByToken}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -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 @@
|
||||
<AuditLogDetails
|
||||
{logs}
|
||||
{selectedId}
|
||||
onFilterToken={(prefix) => {
|
||||
tokenPrefix = prefix
|
||||
onFilterToken={(prefix, at) => {
|
||||
filterByToken(prefix, at)
|
||||
auditLogDrawer?.closeDrawer()
|
||||
}}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user