Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions src/composables/queue/useJobList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,24 +305,40 @@ describe('useJobList', () => {
expect(vi.getTimerCount()).toBe(0)
})

it('sorts all tasks by priority descending', async () => {
it('sorts all tasks by create time', async () => {
queueStoreMock.pendingTasks = [
createTask({ promptId: 'p', queueIndex: 1, mockState: 'pending' })
createTask({
promptId: 'p',
queueIndex: 1,
mockState: 'pending',
createTime: 3000
})
]
queueStoreMock.runningTasks = [
createTask({ promptId: 'r', queueIndex: 5, mockState: 'running' })
createTask({
promptId: 'r',
queueIndex: 5,
mockState: 'running',
createTime: 2000
})
]
queueStoreMock.historyTasks = [
createTask({ promptId: 'h', queueIndex: 3, mockState: 'completed' })
createTask({
promptId: 'h',
queueIndex: 3,
mockState: 'completed',
createTime: 1000,
executionEndTimestamp: 5000
})
]

const { allTasksSorted } = initComposable()
await flush()

expect(allTasksSorted.value.map((task) => task.promptId)).toEqual([
'p',
'r',
'h',
'p'
'h'
])
})

Expand Down
7 changes: 6 additions & 1 deletion src/composables/queue/useJobList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,18 @@ export function useJobList() {
const selectedWorkflowFilter = ref<'all' | 'current'>('all')
const selectedSortMode = ref<JobSortMode>('mostRecent')

const mostRecentTimestamp = (task: TaskItemImpl) => task.createTime ?? 0

Comment on lines +200 to +201
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Prefer function declaration for pure helper functions.

Based on learnings, prefer function mostRecentTimestamp(task: TaskItemImpl) over a const arrow expression for pure functions.

Suggested change
-  const mostRecentTimestamp = (task: TaskItemImpl) => task.createTime ?? 0
+  function mostRecentTimestamp(task: TaskItemImpl): number {
+    return task.createTime ?? 0
+  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const mostRecentTimestamp = (task: TaskItemImpl) => task.createTime ?? 0
function mostRecentTimestamp(task: TaskItemImpl): number {
return task.createTime ?? 0
}
🤖 Prompt for AI Agents
In `@src/composables/queue/useJobList.ts` around lines 200 - 201, Replace the
const arrow helper with a plain function declaration: convert the const
mostRecentTimestamp = (task: TaskItemImpl) => task.createTime ?? 0 into function
mostRecentTimestamp(task: TaskItemImpl) { return task.createTime ?? 0; } so the
pure helper uses a function declaration (keep the TaskItemImpl type and behavior
unchanged and update any local references to mostRecentTimestamp if needed).

const allTasksSorted = computed<TaskItemImpl[]>(() => {
const all = [
...queueStore.pendingTasks,
...queueStore.runningTasks,
...queueStore.historyTasks
]
return all.sort((a, b) => b.queueIndex - a.queueIndex)
return all.sort((a, b) => {
const delta = mostRecentTimestamp(b) - mostRecentTimestamp(a)
return delta === 0 ? 0 : delta
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ternary check delta === 0 ? 0 : delta is redundant. The expression can be simplified to just return delta since returning 0 when delta is 0 and delta otherwise is equivalent to just returning delta.

Suggested change
return delta === 0 ? 0 : delta
return delta

Copilot uses AI. Check for mistakes.
})
Comment on lines +208 to +211
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Redundant ternary expression.

The expression delta === 0 ? 0 : delta always evaluates to delta. Simplify the comparator.

Suggested fix
     return all.sort((a, b) => {
-      const delta = mostRecentTimestamp(b) - mostRecentTimestamp(a)
-      return delta === 0 ? 0 : delta
+      return mostRecentTimestamp(b) - mostRecentTimestamp(a)
     })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return all.sort((a, b) => {
const delta = mostRecentTimestamp(b) - mostRecentTimestamp(a)
return delta === 0 ? 0 : delta
})
return all.sort((a, b) => {
return mostRecentTimestamp(b) - mostRecentTimestamp(a)
})
🤖 Prompt for AI Agents
In `@src/composables/queue/useJobList.ts` around lines 208 - 211, The comparator
inside the return of the all.sort call is using a redundant ternary `delta === 0
? 0 : delta`; replace that with returning delta directly (i.e., return
mostRecentTimestamp(b) - mostRecentTimestamp(a)) in the comparator used in
useJobList.ts so the sort is simplified and no-op branches are removed.

})

const tasksWithJobState = computed<TaskWithState[]>(() =>
Expand Down
Loading