mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-06 16:10:09 +00:00
[feat] Sort history by execution_start timestamp descending
- Modified getHistory method in api.ts to sort history items by execution_start timestamp in descending order (newest first) - Added helper function to extract execution_start timestamp from history item status messages - Maintains backward compatibility with existing API interface
This commit is contained in:
@@ -712,11 +712,26 @@ export class ComfyApi extends EventTarget {
|
||||
try {
|
||||
const res = await this.fetchApi(`/history?max_items=${max_items}`)
|
||||
const json: Promise<HistoryTaskItem[]> = await res.json()
|
||||
const historyItems = Object.values(json).map((item) => ({
|
||||
...item,
|
||||
taskType: 'History'
|
||||
}))
|
||||
|
||||
// Sort by execution_start timestamp in descending order (newest first)
|
||||
historyItems.sort((a, b) => {
|
||||
const getExecutionStartTimestamp = (item: HistoryTaskItem) => {
|
||||
if (!item.status?.messages) return 0
|
||||
const executionStartMessage = item.status.messages.find(
|
||||
(msg) => msg[0] === 'execution_start'
|
||||
)
|
||||
return executionStartMessage ? executionStartMessage[1].timestamp : 0
|
||||
}
|
||||
|
||||
return getExecutionStartTimestamp(b) - getExecutionStartTimestamp(a)
|
||||
})
|
||||
|
||||
return {
|
||||
History: Object.values(json).map((item) => ({
|
||||
...item,
|
||||
taskType: 'History'
|
||||
}))
|
||||
History: historyItems
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
|
||||
Reference in New Issue
Block a user