diff --git a/apps/desktop/src/store/tinybase/store/deleteSession.ts b/apps/desktop/src/store/tinybase/store/deleteSession.ts index 823ce60dde..a386fc8a12 100644 --- a/apps/desktop/src/store/tinybase/store/deleteSession.ts +++ b/apps/desktop/src/store/tinybase/store/deleteSession.ts @@ -25,47 +25,49 @@ export async function deleteSessionCascade( indexes: ReturnType, sessionId: string, ): Promise { - await fsSyncCommands.audioDelete(sessionId); - + // Delete from TinyBase first if (!indexes) { store.delRow("sessions", sessionId); - return; - } + } else { + store.transaction(() => { + const transcriptIds = indexes.getSliceRowIds( + main.INDEXES.transcriptBySession, + sessionId, + ); - store.transaction(() => { - const transcriptIds = indexes.getSliceRowIds( - main.INDEXES.transcriptBySession, - sessionId, - ); + for (const transcriptId of transcriptIds) { + store.delRow("transcripts", transcriptId); + } - for (const transcriptId of transcriptIds) { - store.delRow("transcripts", transcriptId); - } + deleteByIndex( + store, + indexes, + main.INDEXES.sessionParticipantsBySession, + sessionId, + "mapping_session_participant", + ); + deleteByIndex( + store, + indexes, + main.INDEXES.tagSessionsBySession, + sessionId, + "mapping_tag_session", + ); + deleteByIndex( + store, + indexes, + main.INDEXES.enhancedNotesBySession, + sessionId, + "enhanced_notes", + ); - deleteByIndex( - store, - indexes, - main.INDEXES.sessionParticipantsBySession, - sessionId, - "mapping_session_participant", - ); - deleteByIndex( - store, - indexes, - main.INDEXES.tagSessionsBySession, - sessionId, - "mapping_tag_session", - ); - deleteByIndex( - store, - indexes, - main.INDEXES.enhancedNotesBySession, - sessionId, - "enhanced_notes", - ); + store.delRow("sessions", sessionId); + }); + } - store.delRow("sessions", sessionId); - }); + // Explicitly delete the session folder from filesystem + // This replaces reliance on orphan cleanup for session deletion + await fsSyncCommands.deleteSessionFolder(sessionId); } export function useDeleteSession() {