Improve session cache eviction

This commit is contained in:
Shantur Rathore
2025-12-09 14:05:10 +00:00
parent e54f80f20e
commit 8204143810
10 changed files with 319 additions and 100 deletions

View File

@@ -1,4 +1,4 @@
import { Show, createMemo, createEffect, type Component } from "solid-js"
import { Show, createMemo, createEffect, createSignal, type Component } from "solid-js"
import type { Session } from "../../types/session"
import type { Attachment } from "../../types/attachment"
import type { ClientPart } from "../../types/message"
@@ -26,18 +26,25 @@ interface SessionViewProps {
showSidebarToggle?: boolean
onSidebarToggle?: () => void
forceCompactStatusLayout?: boolean
isActive: boolean
}
export const SessionView: Component<SessionViewProps> = (props) => {
const session = () => props.activeSessions.get(props.sessionId)
const messagesLoading = createMemo(() => isSessionMessagesLoading(props.instanceId, props.sessionId))
const messageStore = createMemo(() => messageStoreBus.getOrCreate(props.instanceId))
const [scrollToBottomHandle, setScrollToBottomHandle] = createSignal<(() => void) | null>(null)
createEffect(() => {
if (!props.isActive) return
const handler = scrollToBottomHandle()
if (!handler) return
requestAnimationFrame(() => requestAnimationFrame(() => handler()))
})
const sessionBusy = createMemo(() => {
const currentSession = session()
if (!currentSession) return false
return getSessionBusyStatus(props.instanceId, currentSession.id)
})
let scrollToBottomHandle: (() => void) | undefined
let quoteHandler: ((text: string, mode: "quote" | "code") => void) | null = null
createEffect(() => {
@@ -63,9 +70,9 @@ export const SessionView: Component<SessionViewProps> = (props) => {
}
async function handleSendMessage(prompt: string, attachments: Attachment[]) {
if (scrollToBottomHandle) {
scrollToBottomHandle()
const handler = scrollToBottomHandle()
if (handler) {
handler()
}
await sendMessage(props.instanceId, props.sessionId, prompt, attachments)
}
@@ -193,9 +200,16 @@ export const SessionView: Component<SessionViewProps> = (props) => {
loading={messagesLoading()}
onRevert={handleRevert}
onFork={handleFork}
isActive={props.isActive}
registerScrollToBottom={(fn) => {
scrollToBottomHandle = fn
setScrollToBottomHandle(() => fn)
if (props.isActive) {
requestAnimationFrame(() => requestAnimationFrame(() => fn()))
}
}}
showSidebarToggle={props.showSidebarToggle}
onSidebarToggle={props.onSidebarToggle}
forceCompactStatusLayout={props.forceCompactStatusLayout}