perf(ui): narrow session switch fanout

Keep sidebar rows independent from the active sync directory by moving export history loading behind an explicit-directory command.

Make active-project selection preserve project topology and remove activeProjectId from mounted group render props. Reuse a per-session-array ID index so subscription snapshots do not repeatedly scan session lists.
This commit is contained in:
c_w_xiaohei
2026-08-26 00:44:14 +08:00
parent 701173e399
commit fa1503a038
9 changed files with 74 additions and 39 deletions
+16 -3
View File
@@ -2845,13 +2845,25 @@ export function useScopedBlockingQuestions(sessionID: string | null, directory?:
return useScopedBlockingRequests(sessionID, directory, selectQuestionRequestsBySession, EMPTY_QUESTION_REQUESTS)
}
const sessionsByIdCache = new WeakMap<State["session"], Map<string, Session>>()
const getSessionById = (sessions: State["session"], sessionID?: string | null): Session | undefined => {
if (!sessionID) return undefined
let sessionsById = sessionsByIdCache.get(sessions)
if (!sessionsById) {
sessionsById = new Map(sessions.map((session) => [session.id, session]))
sessionsByIdCache.set(sessions, sessionsById)
}
return sessionsById.get(sessionID)
}
export function useParentSession(sessionID: string | null, directory?: string): Session | null {
return useDirectorySync(
useCallback((state: State) => {
if (!sessionID) return null
const current = state.session.find((s) => s.id === sessionID)
const current = getSessionById(state.session, sessionID)
if (!current?.parentID) return null
return state.session.find((s) => s.id === current.parentID)
return getSessionById(state.session, current.parentID)
?? getAllSyncSessions().find((s) => s.id === current.parentID)
?? null
}, [sessionID]),
@@ -2864,7 +2876,8 @@ export function useSession(sessionID?: string | null, directory?: string) {
const { childStores } = useSyncSystem()
const getSnapshot = useCallback(() => {
if (directory) {
return childStores.getChild(directory)?.getState().session.find((session) => session.id === sessionID)
const sessions = childStores.getChild(directory)?.getState().session
return sessions ? getSessionById(sessions, sessionID) : undefined
}
return findLiveSession(getLiveStates(childStores), sessionID)
}, [childStores, directory, sessionID])