Skip to content

Commit 4fe4433

Browse files
authored
Only validate new history items (#393)
1 parent f987f4f commit 4fe4433

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/stores/queueStore.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,15 @@ interface State {
156156
runningTasks: TaskItemImpl[]
157157
pendingTasks: TaskItemImpl[]
158158
historyTasks: TaskItemImpl[]
159+
maxHistoryItems: number
159160
}
160161

161162
export const useQueueStore = defineStore('queue', {
162163
state: (): State => ({
163164
runningTasks: [],
164165
pendingTasks: [],
165-
historyTasks: []
166+
historyTasks: [],
167+
maxHistoryItems: 64
166168
}),
167169
getters: {
168170
tasks(state) {
@@ -171,14 +173,17 @@ export const useQueueStore = defineStore('queue', {
171173
...state.runningTasks,
172174
...state.historyTasks
173175
]
176+
},
177+
lastHistoryQueueIndex(state) {
178+
return state.historyTasks.length ? state.historyTasks[0].queueIndex : -1
174179
}
175180
},
176181
actions: {
177182
// Fetch the queue data from the API
178183
async update() {
179184
const [queue, history] = await Promise.all([
180185
api.getQueue(),
181-
api.getHistory(/* maxItems=*/ 64)
186+
api.getHistory(this.maxHistoryItems)
182187
])
183188

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

192197
this.runningTasks = toClassAll(queue.Running)
193198
this.pendingTasks = toClassAll(queue.Pending)
194-
this.historyTasks = toClassAll(history.History)
199+
200+
// Process history items
201+
const newHistoryItems = history.History.filter(
202+
(item) => item.prompt[0] > this.lastHistoryQueueIndex
203+
)
204+
205+
if (newHistoryItems.length > 0) {
206+
const newProcessedItems = toClassAll(newHistoryItems)
207+
this.historyTasks = [...newProcessedItems, ...this.historyTasks]
208+
.slice(0, this.maxHistoryItems)
209+
.sort((a, b) => b.queueIndex - a.queueIndex)
210+
}
195211
},
196212
async clear() {
197213
await Promise.all(

0 commit comments

Comments
 (0)