mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-09 19:52:44 +00:00
tui: fix message history cleanup to prevent memory leaks
This commit is contained in:
parent
2542693f7b
commit
aa4b06e165
1 changed files with 19 additions and 1 deletions
|
|
@ -241,9 +241,27 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
|
|||
event.properties.info.sessionID,
|
||||
produce((draft) => {
|
||||
draft.splice(result.index, 0, event.properties.info)
|
||||
if (draft.length > 100) draft.shift()
|
||||
}),
|
||||
)
|
||||
const updated = store.message[event.properties.info.sessionID]
|
||||
if (updated.length > 100) {
|
||||
const oldest = updated[0]
|
||||
batch(() => {
|
||||
setStore(
|
||||
"message",
|
||||
event.properties.info.sessionID,
|
||||
produce((draft) => {
|
||||
draft.shift()
|
||||
}),
|
||||
)
|
||||
setStore(
|
||||
"part",
|
||||
produce((draft) => {
|
||||
delete draft[oldest.id]
|
||||
}),
|
||||
)
|
||||
})
|
||||
}
|
||||
break
|
||||
}
|
||||
case "message.removed": {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue