Only validate new history items (#393)

This commit is contained in:
Chenlei Hu
2024-08-12 20:30:11 -04:00
committed by GitHub
parent f987f4f5f3
commit 4fe44339fd

View File

@@ -156,13 +156,15 @@ interface State {
runningTasks: TaskItemImpl[] runningTasks: TaskItemImpl[]
pendingTasks: TaskItemImpl[] pendingTasks: TaskItemImpl[]
historyTasks: TaskItemImpl[] historyTasks: TaskItemImpl[]
maxHistoryItems: number
} }
export const useQueueStore = defineStore('queue', { export const useQueueStore = defineStore('queue', {
state: (): State => ({ state: (): State => ({
runningTasks: [], runningTasks: [],
pendingTasks: [], pendingTasks: [],
historyTasks: [] historyTasks: [],
maxHistoryItems: 64
}), }),
getters: { getters: {
tasks(state) { tasks(state) {
@@ -171,6 +173,9 @@ export const useQueueStore = defineStore('queue', {
...state.runningTasks, ...state.runningTasks,
...state.historyTasks ...state.historyTasks
] ]
},
lastHistoryQueueIndex(state) {
return state.historyTasks.length ? state.historyTasks[0].queueIndex : -1
} }
}, },
actions: { actions: {
@@ -178,7 +183,7 @@ export const useQueueStore = defineStore('queue', {
async update() { async update() {
const [queue, history] = await Promise.all([ const [queue, history] = await Promise.all([
api.getQueue(), api.getQueue(),
api.getHistory(/* maxItems=*/ 64) api.getHistory(this.maxHistoryItems)
]) ])
const toClassAll = (tasks: TaskItem[]): TaskItemImpl[] => const toClassAll = (tasks: TaskItem[]): TaskItemImpl[] =>
@@ -191,7 +196,18 @@ export const useQueueStore = defineStore('queue', {
this.runningTasks = toClassAll(queue.Running) this.runningTasks = toClassAll(queue.Running)
this.pendingTasks = toClassAll(queue.Pending) this.pendingTasks = toClassAll(queue.Pending)
this.historyTasks = toClassAll(history.History)
// Process history items
const newHistoryItems = history.History.filter(
(item) => item.prompt[0] > this.lastHistoryQueueIndex
)
if (newHistoryItems.length > 0) {
const newProcessedItems = toClassAll(newHistoryItems)
this.historyTasks = [...newProcessedItems, ...this.historyTasks]
.slice(0, this.maxHistoryItems)
.sort((a, b) => b.queueIndex - a.queueIndex)
}
}, },
async clear() { async clear() {
await Promise.all( await Promise.all(