opencode
opencode copied to clipboard
perf: `Session.children()` iterates over all sessions in the project
Issue
The function Session.children() reads ALL the sessions of the project from disk each call to enumerate the child sessions:
export const children = fn(Identifier.schema("session"), async (parentID) => {
const project = Instance.project
const result = [] as Session.Info[]
for (const item of await Storage.list(["session", project.id])) {
const session = await Storage.read<Info>(item)
if (session.parentID !== parentID) continue
result.push(session)
}
return result
})
Suggestion:
introduce a field in the session that lists the child sessions to allow for O(1) access to child sessions