Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(grid): keep the busy overlay elapsed time across result view switches (#12821) (#12842)

弈秋6ff53b30785d
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue
index cf99f048c6..7f438ae6ad 100644
--- a/apps/desktop/src/components/grid/DataGrid.vue
+++ b/apps/desktop/src/components/grid/DataGrid.vue
@@ -113,6 +113,7 @@ import { findTableStatistics } from "@/lib/dataGrid/tableInfoOverview";
import * as api from "@/lib/backend/api";
import type { SqlInsertMode } from "@/lib/export/sqlInsertMode";
import { dataGridCellDisplayText, dataGridCellEditorText } from "@/lib/dataGrid/dataGridCellCoercion";
+import { resolveDataGridBusyStartedAt } from "@/lib/dataGrid/dataGridBusyElapsed";
import { createColumnDrafts } from "@/lib/table/tableStructureEditorState";
import type { BuildSingleColumnAlterSqlOptions } from "@/lib/table/tableStructureEditorSql";
import { buildTableSelectSql, qualifyTableReferencesInSql, quoteTableDataIdentifier } from "@/lib/table/tableSelectSql";
@@ -659,6 +660,13 @@ interface DataGridProps {
cancelling?: boolean;
cancelDisabled?: boolean;
revealColumnRequest?: { id: number; columnName: string };
+ /**
+ * Start of the query execution behind the busy overlay, when the busy surface
+ * is driven by one. Switching the result view unmounts this grid, so the
+ * elapsed pill must read the execution start from the tab instead of the
+ * mount time (issue #12821).
+ */
+ busyStartedAt?: number;
}
const props = withDefaults(defineProps<DataGridProps>(), {
@@ -13449,8 +13457,8 @@ function startLoadingElapsedTimer(reset = false) {
return;
}
if (reset || !_loadingStart) {
- _loadingStart = Date.now();
- loadingElapsed.value = 0;
+ _loadingStart = resolveDataGridBusyStartedAt({ now: Date.now(), reset, currentStartedAt: _loadingStart, executionStartedAt: props.busyStartedAt });
+ loadingElapsed.value = Math.max(0, Date.now() - _loadingStart);
} else {
loadingElapsed.value = Date.now() - _loadingStart;
}
@@ -13486,6 +13494,16 @@ watch(gridSurfaceBusy, (isLoading) => {
}
});
+// A second execution can start while the surface is already busy (a refresh, or
+// a remount that lands after the query started). Re-base the pill on the new
+// execution start instead of keeping the previous baseline.
+watch(
+ () => props.busyStartedAt,
+ () => {
+ if (gridSurfaceBusy.value) startLoadingElapsedTimer(true);
+ },
+);
+
onActivated(() => {
gridClipboardActive = true;
autoRefresh.start();
diff --git a/apps/desktop/src/components/grid/__tests__/DataGridSurfaces.spec.ts b/apps/desktop/src/components/grid/__tests__/DataGridSurfaces.spec.ts
index 0daccb4d99..d106985398 100644
--- a/apps/desktop/src/components/grid/__tests__/DataGridSurfaces.spec.ts
+++ b/apps/desktop/src/components/grid/__tests__/DataGridSurfaces.spec.ts
@@ -1,6 +1,6 @@
// @vitest-environment happy-dom
-import { createApp, defineComponent, h, nextTick } from "vue";
+import { createApp, defineComponent, h, nextTick, shallowRef } from "vue";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { createPinia, setActivePinia } from "pinia";
import { dispatch, findAll, findOne, hostText, mountComponent } from "./vueHostHarness";
@@ -2634,6 +2634,34 @@ describe("DataGrid column header tooltips", () => {
});
});
+describe("DataGrid busy execution elapsed time", () => {
+ it("rebases the displayed elapsed time when another execution starts while loading", async () => {
+ setActivePinia(createPinia());
+ const now = vi.spyOn(Date, "now").mockReturnValue(5_000);
+ const startedAt = shallowRef(1_000);
+ const host = document.createElement("div");
+ document.body.appendChild(host);
+ const app = createApp(defineComponent({ setup: () => () => h(DataGrid, { result: { columns: ["id"], rows: [[1]] }, loading: true, busyStartedAt: startedAt.value }) }));
+ try {
+ app.mount(host);
+ await nextTick();
+ await nextTick();
+ expect(host.textContent).toContain("4.0s");
+
+ now.mockReturnValue(9_000);
+ startedAt.value = 8_000;
+ await nextTick();
+ await nextTick();
+ expect(host.textContent).toContain("1.0s");
+ expect(host.textContent).not.toContain("8.0s");
+ } finally {
+ app.unmount();
+ host.remove();
+ now.mockRestore();
+ }
+ });
+});
+
describe("EnumCellEditor boolean labels", () => {
it("shows TRUE/FALSE but commits the raw boolean value", () => {
const commit = vi.fn();
diff --git a/apps/desktop/src/components/layout/ContentArea.vue b/apps/desktop/src/components/layout/ContentArea.vue
index 16b018a58d..31801c9720 100644
--- a/apps/desktop/src/components/layout/ContentArea.vue
+++ b/apps/desktop/src/components/layout/ContentArea.vue
@@ -2765,6 +2765,7 @@ defineExpose({
:export-sql="activeResultExportSql"
:page-sql="activeTab.resultPageSql"
:loading="activeResultIsLoading"
+ :busy-started-at="activeTab.isExecuting ? activeTab.queryExecutionStartedAt : undefined"
:editable="!hasNeo4jNodes && (!!activeTab.queryAnalysis || !!mongoQueryResultSaveHandler)"
:source-columns="hasNeo4jNodes ? undefined : activeTab.querySourceColumns"
:joined-write-targets="hasNeo4jNodes ? undefined : activeTab.queryWriteTargets"
@@ -3301,6 +3302,7 @@ defineExpose({
:sql="activeTab.sql"
:page-sql="activeTab.resultPageSql || activeTab.sql"
:loading="activeTab.isExecuting"
+ :busy-started-at="activeTab.isExecuting ? activeTab.queryExecutionStartedAt : undefined"
:editable="!activeTab.tableMetaPending && (isTableDataEditable(activeEffectiveDatabaseType, activeTableMeta?.primaryKeys ?? [], activeTableMeta?.tableType) || !!influxDbV1DeleteSaveHandler)"
:custom-save-handler="influxDbV1DeleteSaveHandler"
context="table-data"
diff --git a/apps/desktop/src/lib/dataGrid/__tests__/dataGridBusyElapsed.spec.ts b/apps/desktop/src/lib/dataGrid/__tests__/dataGridBusyElapsed.spec.ts
new file mode 100644
index 0000000000..81485c7fb7
--- /dev/null
+++ b/apps/desktop/src/lib/dataGrid/__tests__/dataGridBusyElapsed.spec.ts
@@ -0,0 +1,38 @@
+import { describe, expect, it } from "vitest";
+import { resolveDataGridBusyStartedAt } from "@/lib/dataGrid/dataGridBusyElapsed";
+
+describe("resolveDataGridBusyStartedAt", () => {
+ it("re-bases a remounted grid on the running query instead of the mount time", () => {
+ // Issue #12821: switching the result view unmounts the grid mid-execution,
+ // so the fresh instance has no baseline of its own. The tab's execution
+ // start must win over "the surface became busy just now".
+ const executionStartedAt = 1_000;
+ const now = 5_000;
+ expect(resolveDataGridBusyStartedAt({ now, reset: true, currentStartedAt: 0, executionStartedAt })).toBe(executionStartedAt);
+ });
+
+ it("keeps the query start when the surface stays busy across a re-base", () => {
+ const executionStartedAt = 1_000;
+ expect(resolveDataGridBusyStartedAt({ now: 9_000, reset: false, currentStartedAt: 8_500, executionStartedAt })).toBe(executionStartedAt);
+ });
+
+ it("starts a busy period that no query execution drives at the current time", () => {
+ expect(resolveDataGridBusyStartedAt({ now: 4_200, reset: true, currentStartedAt: 0 })).toBe(4_200);
+ });
+
+ it("preserves an in-flight non-query busy period when the grid resumes", () => {
+ expect(resolveDataGridBusyStartedAt({ now: 4_200, reset: false, currentStartedAt: 3_000 })).toBe(3_000);
+ });
+
+ it("starts a non-query busy period now when no baseline was captured yet", () => {
+ expect(resolveDataGridBusyStartedAt({ now: 4_200, reset: false, currentStartedAt: 0 })).toBe(4_200);
+ });
+
+ it("clamps a future execution start so the elapsed pill never goes negative", () => {
+ expect(resolveDataGridBusyStartedAt({ now: 4_200, reset: true, currentStartedAt: 0, executionStartedAt: 9_000 })).toBe(4_200);
+ });
+
+ it("ignores a non-finite execution start", () => {
+ expect(resolveDataGridBusyStartedAt({ now: 4_200, reset: true, currentStartedAt: 0, executionStartedAt: Number.NaN })).toBe(4_200);
+ });
+});
diff --git a/apps/desktop/src/lib/dataGrid/dataGridBusyElapsed.ts b/apps/desktop/src/lib/dataGrid/dataGridBusyElapsed.ts
new file mode 100644
index 0000000000..8a2d22c717
--- /dev/null
+++ b/apps/desktop/src/lib/dataGrid/dataGridBusyElapsed.ts
@@ -0,0 +1,35 @@
+/**
+ * Baseline of the data grid busy overlay's elapsed pill.
+ *
+ * `ContentArea` renders only the active result view, so switching between the
+ * table, summary, chart and message views unmounts the grid and mounts a new
+ * instance when the user comes back. The busy overlay's baseline lived in
+ * component state, so a remount during a running query restarted the counter at
+ * zero and the elapsed pill no longer matched the real execution time
+ * (issue #12821).
+ *
+ * The query's own start time is authoritative whenever the busy surface is
+ * driven by a query execution: it lives on the tab, so it survives the
+ * remount. Busy surfaces that no query execution drives (page jumps, row
+ * preparation, background counts) keep the previous per-mount baseline, so
+ * their elapsed pill still starts when the surface became busy.
+ */
+export interface ResolveDataGridBusyStartedAtOptions {
+ /** Current wall clock, in milliseconds. */
+ now: number;
+ /** The caller wants a new busy period to start now. */
+ reset: boolean;
+ /** Baseline of the busy period already running in this grid instance, or 0. */
+ currentStartedAt: number;
+ /** Start of the query execution behind the busy surface, when there is one. */
+ executionStartedAt?: number;
+}
+
+export function resolveDataGridBusyStartedAt(options: ResolveDataGridBusyStartedAtOptions): number {
+ const { now, reset, currentStartedAt, executionStartedAt } = options;
+ // A future timestamp (clock skew, or a tab restored from disk) would render a
+ // negative elapsed time, so it is clamped to "just started".
+ if (executionStartedAt !== undefined && Number.isFinite(executionStartedAt)) return Math.min(executionStartedAt, now);
+ if (reset || !currentStartedAt) return now;
+ return currentStartedAt;
+}