-
Notifications
You must be signed in to change notification settings - Fork 491
fix: sort queue jobs by create time #8225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||||||||||||
|
|
||||||||||||||||
| 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 | ||||||||||||||||
|
||||||||||||||||
| return delta === 0 ? 0 : delta | |
| return delta |
There was a problem hiding this comment.
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.
| 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.
There was a problem hiding this comment.
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
📝 Committable suggestion
🤖 Prompt for AI Agents