Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
"@t3-oss/env-core": "^0.13.8",
"@tanstack/db": "0.6.5",
"@tanstack/electric-db-collection": "0.3.3",
"@tanstack/electron-db-sqlite-persistence": "0.1.9",
"@tanstack/node-db-sqlite-persistence": "0.1.9",
"@tanstack/react-db": "0.1.83",
"@tanstack/react-query": "^5.90.19",
"@tanstack/react-router": "^1.147.3",
Expand Down
6 changes: 6 additions & 0 deletions apps/desktop/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import { loadWebviewBrowserExtension } from "./lib/extensions";
import { getHostServiceCoordinator } from "./lib/host-service-coordinator";
import { localDb } from "./lib/local-db";
import { requestLocalNetworkAccess } from "./lib/local-network-permission";
import {
initTanstackDbPersistence,
shutdownTanstackDbPersistence,
} from "./lib/persistence/persistence";
import { ensureProjectIconsDir, getProjectIconPath } from "./lib/project-icons";
import { initSentry } from "./lib/sentry";
import {
Expand Down Expand Up @@ -207,6 +211,7 @@ app.on("before-quit", async (event) => {
isQuitting = true;
try {
getHostServiceCoordinator().releaseAll();
shutdownTanstackDbPersistence();
disposeTray();
} catch (error) {
console.error("[main] Cleanup during quit failed:", error);
Expand Down Expand Up @@ -345,6 +350,7 @@ if (!gotTheLock) {
setWorkspaceDockIcon();
initSentry();
await initAppState();
initTanstackDbPersistence();

await loadWebviewBrowserExtension();

Expand Down
26 changes: 26 additions & 0 deletions apps/desktop/src/main/lib/persistence/persistence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { join } from "node:path";
import { exposeElectronSQLitePersistence } from "@tanstack/electron-db-sqlite-persistence/main";
import { createNodeSQLitePersistence } from "@tanstack/node-db-sqlite-persistence";
import Database from "better-sqlite3";
import { ipcMain } from "electron";
import {
ensureSupersetHomeDirExists,
SUPERSET_HOME_DIR,
} from "../app-environment";

let dispose: (() => void) | null = null;
let database: Database.Database | null = null;

export function initTanstackDbPersistence(): void {
ensureSupersetHomeDirExists();
database = new Database(join(SUPERSET_HOME_DIR, "tanstack-db.sqlite"));
const persistence = createNodeSQLitePersistence({ database });
dispose = exposeElectronSQLitePersistence({ ipcMain, persistence });
}

export function shutdownTanstackDbPersistence(): void {
dispose?.();
dispose = null;
database?.close();
database = null;
}
Comment on lines +11 to +26
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Database handle not closed on shutdown

database is a local variable — only dispose (the IPC-handler teardown returned by exposeElectronSQLitePersistence) is kept in module scope. Calling shutdownTanstackDbPersistence removes the IPC handlers but never calls database.close(). On before-quit the process then force-exits via app.exit(0). While the OS will release file locks, SQLite may not flush its page cache or checkpoint a WAL file cleanly, which is exactly what the test plan item "No SQLite lockfile / WAL stragglers in ~/.superset/" is testing for.

Store the database reference at module scope alongside dispose so shutdown can close it explicitly:

let dispose: (() => void) | null = null;
let db: Database.Database | null = null;

export function initTanstackDbPersistence(): void {
  ensureSupersetHomeDirExists();
  db = new Database(join(SUPERSET_HOME_DIR, "tanstack-db.sqlite"));
  const persistence = createNodeSQLitePersistence({ database: db });
  dispose = exposeElectronSQLitePersistence({ ipcMain, persistence });
}

export function shutdownTanstackDbPersistence(): void {
  dispose?.();
  dispose = null;
  db?.close();
  db = null;
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/main/lib/persistence/persistence.ts
Line: 11-23

Comment:
**Database handle not closed on shutdown**

`database` is a local variable — only `dispose` (the IPC-handler teardown returned by `exposeElectronSQLitePersistence`) is kept in module scope. Calling `shutdownTanstackDbPersistence` removes the IPC handlers but never calls `database.close()`. On `before-quit` the process then force-exits via `app.exit(0)`. While the OS will release file locks, SQLite may not flush its page cache or checkpoint a WAL file cleanly, which is exactly what the test plan item "No SQLite lockfile / WAL stragglers in `~/.superset/`" is testing for.

Store the database reference at module scope alongside `dispose` so shutdown can close it explicitly:

```ts
let dispose: (() => void) | null = null;
let db: Database.Database | null = null;

export function initTanstackDbPersistence(): void {
  ensureSupersetHomeDirExists();
  db = new Database(join(SUPERSET_HOME_DIR, "tanstack-db.sqlite"));
  const persistence = createNodeSQLitePersistence({ database: db });
  dispose = exposeElectronSQLitePersistence({ ipcMain, persistence });
}

export function shutdownTanstackDbPersistence(): void {
  dispose?.();
  dispose = null;
  db?.close();
  db = null;
}
```

How can I resolve this? If you propose a fix, please make it concise.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Spinner } from "@superset/ui/spinner";
import { useLiveQuery } from "@tanstack/react-db";
import { useNavigate } from "@tanstack/react-router";
import { useCallback, useEffect, useRef, useState } from "react";
Expand Down Expand Up @@ -78,7 +77,7 @@ export function TasksView({
storeSetSearch(searchQuery);
}, [searchQuery, storeSetSearch]);

const { data: integrations, isLoading: isCheckingLinear } = useLiveQuery(
const { data: integrations } = useLiveQuery(
(q) =>
q
.from({ integrationConnections: collections.integrationConnections })
Expand Down Expand Up @@ -134,7 +133,7 @@ export function TasksView({
});
};

const showLinearCTA = !isCheckingLinear && !isLinearConnected;
const showLinearCTA = integrations !== undefined && !isLinearConnected;

return (
<div className="flex-1 flex flex-col min-h-0 min-w-0 overflow-hidden">
Expand All @@ -153,11 +152,7 @@ export function TasksView({
/>
)}

{isCheckingLinear ? (
<div className="flex-1 flex items-center justify-center">
<Spinner className="size-5" />
</div>
) : showLinearCTA ? (
{showLinearCTA ? (
<LinearCTA />
) : viewMode === "board" ? (
<BoardContent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Spinner } from "@superset/ui/spinner";
import { HiCheckCircle } from "react-icons/hi2";
import type { TaskWithStatus } from "../../hooks/useTasksData";
import { useTasksData } from "../../hooks/useTasksData";
Expand All @@ -18,20 +17,12 @@ export function BoardContent({
assigneeFilter,
onTaskClick,
}: BoardContentProps) {
const { data, allStatuses, isLoading } = useTasksData({
const { data, allStatuses } = useTasksData({
filterTab,
searchQuery,
assigneeFilter,
});

if (isLoading) {
return (
<div className="flex-1 flex items-center justify-center">
<Spinner className="size-5" />
</div>
);
}

if (data.length === 0) {
return (
<div className="flex-1 flex items-center justify-center">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Spinner } from "@superset/ui/spinner";
import { useCallback, useEffect, useMemo } from "react";
import { HiCheckCircle } from "react-icons/hi2";
import type { TaskWithStatus } from "../../hooks/useTasksData";
Expand All @@ -25,7 +24,7 @@ export function TableContent({
onTaskClick,
onSelectionChange,
}: TableContentProps) {
const { table, isLoading, slugColumnWidth, rowSelection, setRowSelection } =
const { table, slugColumnWidth, rowSelection, setRowSelection } =
useTasksTable({
filterTab,
searchQuery,
Expand All @@ -44,14 +43,6 @@ export function TableContent({
onSelectionChange?.(selectedTasks, clearSelection);
}, [selectedTasks, clearSelection, onSelectionChange]);

if (isLoading) {
return (
<div className="flex-1 flex items-center justify-center">
<Spinner className="size-5" />
</div>
);
}

if (table.getRowModel().rows.length === 0) {
return (
<div className="flex-1 flex items-center justify-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ export function useTasksData({
}: UseTasksDataParams): {
data: TaskWithStatus[];
allStatuses: SelectTaskStatus[];
isLoading: boolean;
} {
const collections = useCollections();

const { data: allData, isLoading } = useLiveQuery(
const { data: allData } = useLiveQuery(
(q) =>
q
.from({ tasks: collections.tasks })
Expand All @@ -52,7 +51,7 @@ export function useTasksData({
[collections],
);

const { data: statusData, isLoading: isStatusesLoading } = useLiveQuery(
const { data: statusData } = useLiveQuery(
(q) =>
q
.from({ taskStatuses: collections.taskStatuses })
Expand Down Expand Up @@ -119,6 +118,5 @@ export function useTasksData({
return {
data: filteredData,
allStatuses,
isLoading: isLoading || isStatusesLoading,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export function useTasksTable({
assigneeFilter,
}: UseTasksTableParams): {
table: Table<TaskWithStatus>;
isLoading: boolean;
slugColumnWidth: string;
rowSelection: RowSelectionState;
setRowSelection: (
Expand All @@ -87,7 +86,7 @@ export function useTasksTable({
const rowSelection = useRowSelectionStore((s) => s.rowSelection);
const setRowSelection = useRowSelectionStore((s) => s.setRowSelection);

const { data: allData, isLoading } = useLiveQuery(
const { data: allData } = useLiveQuery(
(q) =>
q
.from({ tasks: collections.tasks })
Expand Down Expand Up @@ -348,5 +347,5 @@ export function useTasksTable({
autoResetExpanded: false,
});

return { table, isLoading, slugColumnWidth, rowSelection, setRowSelection };
return { table, slugColumnWidth, rowSelection, setRowSelection };
}
Loading
Loading