Skip to content

Commit

Permalink
Only validate new history items (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei authored Aug 13, 2024
1 parent f987f4f commit 4fe4433
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/stores/queueStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,15 @@ interface State {
runningTasks: TaskItemImpl[]
pendingTasks: TaskItemImpl[]
historyTasks: TaskItemImpl[]
maxHistoryItems: number
}

export const useQueueStore = defineStore('queue', {
state: (): State => ({
runningTasks: [],
pendingTasks: [],
historyTasks: []
historyTasks: [],
maxHistoryItems: 64
}),
getters: {
tasks(state) {
Expand All @@ -171,14 +173,17 @@ export const useQueueStore = defineStore('queue', {
...state.runningTasks,
...state.historyTasks
]
},
lastHistoryQueueIndex(state) {
return state.historyTasks.length ? state.historyTasks[0].queueIndex : -1
}
},
actions: {
// Fetch the queue data from the API
async update() {
const [queue, history] = await Promise.all([
api.getQueue(),
api.getHistory(/* maxItems=*/ 64)
api.getHistory(this.maxHistoryItems)
])

const toClassAll = (tasks: TaskItem[]): TaskItemImpl[] =>
Expand All @@ -191,7 +196,18 @@ export const useQueueStore = defineStore('queue', {

this.runningTasks = toClassAll(queue.Running)
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() {
await Promise.all(
Expand Down

0 comments on commit 4fe4433

Please sign in to comment.