mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Fix performance optimizations for permission handling and session management (#32)
This commit is contained in:
1 parent
b28f069576
commit
923b70833d
3 files changed
+47
-12
No files matched your search
@@ -35,19 +35,21 @@ export const SessionList = ({
|
||||
|
||||
const filteredSessions = useMemo(() => {
|
||||
if (!sessions) return [];
|
||||
|
||||
const rootSessions = sessions.filter((session) => {
|
||||
|
||||
let filtered = sessions.filter((session) => {
|
||||
if (session.parentID) return false;
|
||||
if (directory && session.directory && session.directory !== directory) return false;
|
||||
return true;
|
||||
});
|
||||
|
||||
if (!searchQuery.trim()) return rootSessions;
|
||||
|
||||
const query = searchQuery.toLowerCase();
|
||||
return rootSessions.filter((session) =>
|
||||
(session.title || "Untitled Session").toLowerCase().includes(query),
|
||||
);
|
||||
if (searchQuery.trim()) {
|
||||
const query = searchQuery.toLowerCase();
|
||||
filtered = filtered.filter((session) =>
|
||||
(session.title || "Untitled Session").toLowerCase().includes(query),
|
||||
);
|
||||
}
|
||||
|
||||
return filtered.sort((a, b) => b.time.updated - a.time.updated);
|
||||
}, [sessions, searchQuery, directory]);
|
||||
|
||||
if (isLoading) {
|
||||
|
||||
@@ -36,6 +36,7 @@ const PermissionContext = createContext<PermissionContextValue | null>(null)
|
||||
function useActiveRepos(queryClient: ReturnType<typeof useQueryClient>): ActiveRepo[] {
|
||||
const [activeRepos, setActiveRepos] = useState<ActiveRepo[]>([])
|
||||
const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
||||
const lastProcessedRef = useRef<string[]>([])
|
||||
|
||||
useEffect(() => {
|
||||
const checkRepos = () => {
|
||||
@@ -102,8 +103,19 @@ function useActiveRepos(queryClient: ReturnType<typeof useQueryClient>): ActiveR
|
||||
sessions: Array.from(sessionIds).map((id) => ({ id })),
|
||||
}))
|
||||
|
||||
setActiveRepos(repos)
|
||||
}, 0)
|
||||
const currentKeys = repos.map(r => `${r.url}|${r.directory ?? ''}`)
|
||||
const prevKeys = lastProcessedRef.current
|
||||
const currentSet = new Set(currentKeys)
|
||||
const prevSet = new Set(prevKeys)
|
||||
|
||||
const hasChanged = currentSet.size !== prevSet.size ||
|
||||
currentKeys.some(k => !prevSet.has(k))
|
||||
|
||||
if (hasChanged) {
|
||||
setActiveRepos(repos)
|
||||
lastProcessedRef.current = currentKeys
|
||||
}
|
||||
}, 100)
|
||||
}
|
||||
|
||||
checkRepos()
|
||||
|
||||
@@ -8,6 +8,7 @@ export type SessionStatusType =
|
||||
|
||||
interface SessionStatusStore {
|
||||
statuses: Map<string, SessionStatusType>
|
||||
statusCache: Map<string, string>
|
||||
setStatus: (sessionID: string, status: SessionStatusType) => void
|
||||
getStatus: (sessionID: string) => SessionStatusType
|
||||
clearStatus: (sessionID: string) => void
|
||||
@@ -15,14 +16,29 @@ interface SessionStatusStore {
|
||||
|
||||
const DEFAULT_STATUS: SessionStatusType = { type: 'idle' }
|
||||
|
||||
const getStatusHash = (status: SessionStatusType): string => {
|
||||
if (status.type === 'retry') {
|
||||
return `${status.type}:${status.attempt}:${status.message}:${status.next}`
|
||||
}
|
||||
return status.type
|
||||
}
|
||||
|
||||
export const useSessionStatus = create<SessionStatusStore>((set, get) => ({
|
||||
statuses: new Map(),
|
||||
statusCache: new Map(),
|
||||
|
||||
setStatus: (sessionID: string, status: SessionStatusType) => {
|
||||
const hash = getStatusHash(status)
|
||||
const previousHash = get().statusCache.get(sessionID)
|
||||
|
||||
if (previousHash === hash) return
|
||||
|
||||
set((state) => {
|
||||
const newMap = new Map(state.statuses)
|
||||
const newCache = new Map(state.statusCache)
|
||||
newMap.set(sessionID, status)
|
||||
return { statuses: newMap }
|
||||
newCache.set(sessionID, hash)
|
||||
return { statuses: newMap, statusCache: newCache }
|
||||
})
|
||||
},
|
||||
|
||||
@@ -31,10 +47,15 @@ export const useSessionStatus = create<SessionStatusStore>((set, get) => ({
|
||||
},
|
||||
|
||||
clearStatus: (sessionID: string) => {
|
||||
const previousHash = get().statusCache.get(sessionID)
|
||||
if (!previousHash) return
|
||||
|
||||
set((state) => {
|
||||
const newMap = new Map(state.statuses)
|
||||
const newCache = new Map(state.statusCache)
|
||||
newMap.delete(sessionID)
|
||||
return { statuses: newMap }
|
||||
newCache.delete(sessionID)
|
||||
return { statuses: newMap, statusCache: newCache }
|
||||
})
|
||||
},
|
||||
}))
|
||||
|
||||
Reference in new issue
Block a user