diff --git a/web-studio/src/routes/tasks/-lib/task-query.test.ts b/web-studio/src/routes/tasks/-lib/task-query.test.ts new file mode 100644 index 0000000000..5ba91ef884 --- /dev/null +++ b/web-studio/src/routes/tasks/-lib/task-query.test.ts @@ -0,0 +1,13 @@ +import { describe, expect, it } from 'vitest' + +import { buildTaskQuery } from './task-query' + +describe('buildTaskQuery', () => { + it('keeps the recent task query within the server limit', () => { + expect(buildTaskQuery('24h', 'all').limit).toBe(200) + }) + + it('keeps the all-task query within the server limit', () => { + expect(buildTaskQuery('all', 'all').limit).toBe(200) + }) +}) diff --git a/web-studio/src/routes/tasks/-lib/task-query.ts b/web-studio/src/routes/tasks/-lib/task-query.ts new file mode 100644 index 0000000000..0639ce61b2 --- /dev/null +++ b/web-studio/src/routes/tasks/-lib/task-query.ts @@ -0,0 +1,13 @@ +export type TaskDataScope = '24h' | 'all' + +// The server validates this endpoint with `limit <= 200`. +export const TASK_QUERY_LIMIT = 200 + +export function buildTaskQuery(dataScope: TaskDataScope, taskType: string) { + return { + limit: TASK_QUERY_LIMIT, + status: undefined, + task_type: taskType === 'all' ? undefined : taskType, + include_archived: dataScope === 'all' ? true : undefined, + } +} diff --git a/web-studio/src/routes/tasks/route.tsx b/web-studio/src/routes/tasks/route.tsx index 5fdf1e16f8..c1f53903bb 100644 --- a/web-studio/src/routes/tasks/route.tsx +++ b/web-studio/src/routes/tasks/route.tsx @@ -55,6 +55,7 @@ import { } from '#/routes/tasks/-lib/task-record' import type { TaskRecord, TaskStatus } from '#/routes/tasks/-lib/task-record' import { formatTaskDuration, getTaskDate } from '#/routes/tasks/-lib/task-time' +import { buildTaskQuery } from './-lib/task-query' import { getTaskPipelineGroups } from './-lib/task-pipeline' export const Route = createFileRoute('/tasks')({ @@ -75,7 +76,6 @@ type TaskTypeFilter = | 'all' const DEFAULT_PAGE_SIZE = 20 -const MAX_TASKS = 300 const PAGE_SIZE_OPTIONS = [20, 50, 100] as const const TASK_TYPE_OPTIONS: Exclude[] = [ 'session_commit', @@ -116,12 +116,7 @@ async function fetchTasks( status: TaskStatusFilter, dataScope: TaskDataScope = '24h', ): Promise { - const query = { - limit: dataScope === 'all' ? 10000 : MAX_TASKS, - status: undefined, - task_type: taskType === 'all' ? undefined : taskType, - include_archived: dataScope === 'all' ? true : undefined, - } + const query = buildTaskQuery(dataScope, taskType) try { const result = await getOvResult( getTasks({