Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions apps/desktop/src/store/tinybase/persister/local/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ export function useLocalPersister(store: Store) {
await persister.load();

if (getCurrentWebviewWindowLabel() === "main") {
const migrated = migrateWordsAndHintsToTranscripts(store as Store);
if (migrated) {
if (migrateWordsAndHintsToTranscripts(store as Store)) {
await persister.save();
}
}
Expand Down
57 changes: 57 additions & 0 deletions apps/desktop/src/store/tinybase/store/initialize.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { useEffect } from "react";

import { commands as db2Commands } from "@hypr/plugin-db2";
import { getCurrentWebviewWindowLabel } from "@hypr/plugin-windows";

import { DEFAULT_USER_ID } from "../../../utils";
import { STORE_ID } from "./main";
import type { Store } from "./main";

export function useInitializeStore(store: Store): void {
Expand All @@ -10,8 +14,61 @@ export function useInitializeStore(store: Store): void {
}

initializeStore(store);
void cleanupSqliteSessions();
}, [store]);
}

async function cleanupSqliteSessions(): Promise<void> {
if (getCurrentWebviewWindowLabel() !== "main") {
return;
}

const SESSION_TABLES = [
"sessions",
"mapping_session_participant",
"tags",
"mapping_tag_session",
"transcripts",
"enhanced_notes",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Tags table deletion may delete non-session-related tags

The SESSION_TABLES array at initialize.ts:26-32 includes the tags table, and the cleanup deletes all entries matching tags/% from SQLite.

However, tags might be a shared resource used by entities other than sessions. Deleting all tags when cleaning up session data could cause data loss for other features that rely on tags.

The PR description explicitly calls this out: "Verify tags table deletion is correct - The tags table is included in SESSION_TABLES, but tags might be shared across other entities. Confirm that deleting all tags is the intended behavior."

Recommendation: Review whether tags are session-specific or shared. If shared, remove 'tags' from SESSION_TABLES or only delete tags that are linked to sessions via the mapping_tag_session table.

🛟 Review with Devin


Was this helpful? React with 👍 or 👎 to provide feedback.

] as const;

try {
const checkResult = await db2Commands.executeLocal(
`SELECT COUNT(*) as count FROM ${STORE_ID} WHERE _key LIKE 'sessions/%'`,
[],
);

if (checkResult.status === "error" || !checkResult.data?.[0]) {
return;
}

const row = checkResult.data[0];
if (typeof row !== "object" || row === null || !("count" in row)) {
return;
}

const sessionCount = row.count as number;
if (sessionCount === 0) {
return;
}

console.log(
`[Migration] Cleaning up ${sessionCount} session records from SQLite`,
);

for (const table of SESSION_TABLES) {
await db2Commands.executeLocal(
`DELETE FROM ${STORE_ID} WHERE _key LIKE ?`,
[`${table}/%`],
);
}

console.log("[Migration] Session cleanup complete");
} catch (error) {
console.error("[Migration] Failed to cleanup SQLite sessions:", error);
}
}

function initializeStore(store: Store): void {
store.transaction(() => {
if (!store.hasValue("user_id")) {
Expand Down
Loading