fix: skip stale session directories (issue #1010)
Filter active sessions to known project and worktree directories Stop probing session directories with filesystem listing
This commit is contained in:
@@ -28,7 +28,6 @@ import { useProjectSessionSelection } from './sidebar/hooks/useProjectSessionSel
|
|||||||
import { useGroupOrdering } from './sidebar/hooks/useGroupOrdering';
|
import { useGroupOrdering } from './sidebar/hooks/useGroupOrdering';
|
||||||
import { useSessionGrouping } from './sidebar/hooks/useSessionGrouping';
|
import { useSessionGrouping } from './sidebar/hooks/useSessionGrouping';
|
||||||
import { useSessionSearchEffects } from './sidebar/hooks/useSessionSearchEffects';
|
import { useSessionSearchEffects } from './sidebar/hooks/useSessionSearchEffects';
|
||||||
import { useDirectoryStatusProbe } from './sidebar/hooks/useDirectoryStatusProbe';
|
|
||||||
import { useSessionActions } from './sidebar/hooks/useSessionActions';
|
import { useSessionActions } from './sidebar/hooks/useSessionActions';
|
||||||
import { useSidebarPersistence } from './sidebar/hooks/useSidebarPersistence';
|
import { useSidebarPersistence } from './sidebar/hooks/useSidebarPersistence';
|
||||||
import { useProjectRepoStatus } from './sidebar/hooks/useProjectRepoStatus';
|
import { useProjectRepoStatus } from './sidebar/hooks/useProjectRepoStatus';
|
||||||
@@ -74,7 +73,7 @@ import {
|
|||||||
formatProjectLabel,
|
formatProjectLabel,
|
||||||
normalizePath,
|
normalizePath,
|
||||||
} from './sidebar/utils';
|
} from './sidebar/utils';
|
||||||
import { refreshGlobalSessions, useGlobalSessionsStore } from '@/stores/useGlobalSessionsStore';
|
import { refreshGlobalSessions, resolveGlobalSessionDirectory, useGlobalSessionsStore } from '@/stores/useGlobalSessionsStore';
|
||||||
import { useRuntimeAPIs } from '@/hooks/useRuntimeAPIs';
|
import { useRuntimeAPIs } from '@/hooks/useRuntimeAPIs';
|
||||||
import { useGitHubAuthStore } from '@/stores/useGitHubAuthStore';
|
import { useGitHubAuthStore } from '@/stores/useGitHubAuthStore';
|
||||||
import { subscribeOpenchamberEvents } from '@/lib/openchamberEvents';
|
import { subscribeOpenchamberEvents } from '@/lib/openchamberEvents';
|
||||||
@@ -112,6 +111,32 @@ type PrIndicator = {
|
|||||||
} | null;
|
} | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const buildKnownSessionDirectories = (
|
||||||
|
projects: Array<{ path: string }>,
|
||||||
|
availableWorktreesByProject: Map<string, WorktreeMetadata[]>,
|
||||||
|
): Set<string> => {
|
||||||
|
const directories = new Set<string>();
|
||||||
|
for (const project of projects) {
|
||||||
|
const normalized = normalizePath(project.path)?.toLowerCase();
|
||||||
|
if (normalized) directories.add(normalized);
|
||||||
|
}
|
||||||
|
for (const worktrees of availableWorktreesByProject.values()) {
|
||||||
|
for (const worktree of worktrees) {
|
||||||
|
const normalized = normalizePath(worktree.path)?.toLowerCase();
|
||||||
|
if (normalized) directories.add(normalized);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return directories;
|
||||||
|
};
|
||||||
|
|
||||||
|
const isKnownActiveSessionDirectory = (session: Session, knownDirectories: Set<string>): boolean => {
|
||||||
|
if (session.time?.archived) return true;
|
||||||
|
const directory = normalizePath(resolveGlobalSessionDirectory(session))?.toLowerCase();
|
||||||
|
if (!directory) return true;
|
||||||
|
if (knownDirectories.size === 0) return true;
|
||||||
|
return knownDirectories.has(directory);
|
||||||
|
};
|
||||||
|
|
||||||
interface SessionSidebarProps {
|
interface SessionSidebarProps {
|
||||||
mobileVariant?: boolean;
|
mobileVariant?: boolean;
|
||||||
onSessionSelected?: (sessionId: string) => void;
|
onSessionSelected?: (sessionId: string) => void;
|
||||||
@@ -136,7 +161,7 @@ export const SessionSidebar: React.FC<SessionSidebarProps> = ({
|
|||||||
const [editTitle, setEditTitle] = React.useState('');
|
const [editTitle, setEditTitle] = React.useState('');
|
||||||
const [editingProjectDialogId, setEditingProjectDialogId] = React.useState<string | null>(null);
|
const [editingProjectDialogId, setEditingProjectDialogId] = React.useState<string | null>(null);
|
||||||
const [expandedParents, setExpandedParents] = React.useState<Set<string>>(new Set());
|
const [expandedParents, setExpandedParents] = React.useState<Set<string>>(new Set());
|
||||||
const [directoryStatus, setDirectoryStatus] = React.useState<Map<string, 'unknown' | 'exists' | 'missing'>>(
|
const [directoryStatus] = React.useState<Map<string, 'unknown' | 'exists' | 'missing'>>(
|
||||||
() => new Map(),
|
() => new Map(),
|
||||||
);
|
);
|
||||||
const safeStorage = React.useMemo(() => getSafeStorage(), []);
|
const safeStorage = React.useMemo(() => getSafeStorage(), []);
|
||||||
@@ -304,6 +329,11 @@ export const SessionSidebar: React.FC<SessionSidebarProps> = ({
|
|||||||
restartToUpdate: s.restartToUpdate,
|
restartToUpdate: s.restartToUpdate,
|
||||||
})));
|
})));
|
||||||
|
|
||||||
|
const knownSessionDirectories = React.useMemo(
|
||||||
|
() => buildKnownSessionDirectories(projects, availableWorktreesByProject),
|
||||||
|
[availableWorktreesByProject, projects],
|
||||||
|
);
|
||||||
|
|
||||||
const sessions = React.useMemo(() => {
|
const sessions = React.useMemo(() => {
|
||||||
const liveById = new Map(liveSessions.map((session) => [session.id, session]));
|
const liveById = new Map(liveSessions.map((session) => [session.id, session]));
|
||||||
const merged = globalActiveSessions.map((session) => liveById.get(session.id) ?? session);
|
const merged = globalActiveSessions.map((session) => liveById.get(session.id) ?? session);
|
||||||
@@ -316,8 +346,8 @@ export const SessionSidebar: React.FC<SessionSidebarProps> = ({
|
|||||||
merged.push(session);
|
merged.push(session);
|
||||||
});
|
});
|
||||||
|
|
||||||
return merged;
|
return merged.filter((session) => isKnownActiveSessionDirectory(session, knownSessionDirectories));
|
||||||
}, [globalActiveSessions, liveSessions]);
|
}, [globalActiveSessions, knownSessionDirectories, liveSessions]);
|
||||||
|
|
||||||
const syncSessionStructureSignature = React.useMemo(
|
const syncSessionStructureSignature = React.useMemo(
|
||||||
() => liveSessions
|
() => liveSessions
|
||||||
@@ -547,13 +577,6 @@ export const SessionSidebar: React.FC<SessionSidebarProps> = ({
|
|||||||
return map;
|
return map;
|
||||||
}, [sortedSessions, pinnedSessionIds]);
|
}, [sortedSessions, pinnedSessionIds]);
|
||||||
|
|
||||||
useDirectoryStatusProbe({
|
|
||||||
sortedSessions,
|
|
||||||
projects,
|
|
||||||
directoryStatus,
|
|
||||||
setDirectoryStatus,
|
|
||||||
});
|
|
||||||
|
|
||||||
const emptyState = (
|
const emptyState = (
|
||||||
<div className="py-6 text-center text-muted-foreground">
|
<div className="py-6 text-center text-muted-foreground">
|
||||||
<p className="typography-ui-label font-semibold">{t('sessions.sidebar.empty.noSessions.title')}</p>
|
<p className="typography-ui-label font-semibold">{t('sessions.sidebar.empty.noSessions.title')}</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user