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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(desktop): format loading elapsed time
t8y28883a6b3b707
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vueindex 6901ac5e9d..26604f593c 100644--- a/apps/desktop/src/components/grid/DataGrid.vue+++ b/apps/desktop/src/components/grid/DataGrid.vue@@ -87,6 +87,7 @@ import TemporalCellEditor from "@/components/grid/TemporalCellEditor.vue";import EnumCellEditor from "@/components/grid/EnumCellEditor.vue";import type { QueryResult, ColumnInfo, DatabaseType, ForeignKeyInfo, IndexInfo, TriggerInfo, TableInfoTab } from "@/types/database";import * as api from "@/lib/backend/api";+import { formatElapsedSeconds } from "@/lib/common/elapsedTime";import { dataGridCellDisplayText, dataGridCellEditorText } from "@/lib/dataGrid/dataGridCellCoercion";import { createColumnDrafts } from "@/lib/table/tableStructureEditorState";import type { BuildSingleColumnAlterSqlOptions } from "@/lib/table/tableStructureEditorSql";@@ -7652,12 +7653,14 @@ function onDetailResizeEnd() {}const loadingElapsed = ref(0);-let _loadingTimer: ReturnType<typeof setInterval> | undefined;+let _loadingFrame: number | undefined;let _loadingStart = 0;function stopLoadingElapsedTimer() {- clearInterval(_loadingTimer);- _loadingTimer = undefined;+ if (_loadingFrame !== undefined) {+ window.cancelAnimationFrame(_loadingFrame);+ _loadingFrame = undefined;+ }}function startLoadingElapsedTimer() {@@ -7665,9 +7668,12 @@ function startLoadingElapsedTimer() {if (!dataGridIsActive || !props.loading) return;_loadingStart = Date.now();loadingElapsed.value = 0;- _loadingTimer = setInterval(() => {+ const updateOnNextFrame = () => {+ if (!dataGridIsActive || !props.loading) return;loadingElapsed.value = Date.now() - _loadingStart;- }, 100);+ _loadingFrame = window.requestAnimationFrame(updateOnNextFrame);+ };+ _loadingFrame = window.requestAnimationFrame(updateOnNextFrame);}watch(@@ -7716,7 +7722,7 @@ onUnmounted(() => {if (serverFilterSearchTimer !== undefined) {window.clearTimeout(serverFilterSearchTimer);}- clearInterval(_loadingTimer);+ stopLoadingElapsedTimer();});const filteredColumns = computed(() => {@@ -9496,7 +9502,7 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {<div v-if="loading" class="absolute inset-0 z-20 bg-background/50 flex items-center justify-center"><div class="flex items-center gap-2 px-3 py-1.5 rounded-md bg-background border shadow-sm text-xs text-muted-foreground"><Loader2 class="w-3.5 h-3.5 animate-spin" />- <span>{{ (loadingElapsed / 1000).toFixed(1) }}s</span>+ <span>{{ formatElapsedSeconds(loadingElapsed) }}s</span></div></div></template>diff --git a/apps/desktop/src/components/layout/ContentArea.vue b/apps/desktop/src/components/layout/ContentArea.vueindex 56c0455cab..4e82e0ceac 100644--- a/apps/desktop/src/components/layout/ContentArea.vue+++ b/apps/desktop/src/components/layout/ContentArea.vue@@ -67,6 +67,7 @@ import { buildMongoUpdateDocument, formatMongoShellLiteral, type MongoInputValueimport type { SqlExecutionOverride } from "@/lib/sql/sqlExecutionTarget";import type { DataGridSortMode } from "@/lib/dataGrid/dataGridSort";import { useTabScroll } from "@/composables/useTabScroll";+import { formatElapsedSeconds } from "@/lib/common/elapsedTime";import type { CustomSaveHandler } from "@/composables/useDataGridEditor";import type { QueryTab, ConnectionConfig, TableInfoTab, TreeNode, VectorCollectionMeta } from "@/types/database";import { sqlFormatDialectForDbType, type SqlFormatDialect } from "@/lib/sql/sqlFormatter";@@ -376,11 +377,13 @@ function onResultsResized(payload: { panes: { size: number }[] }) {safeLocalStorageSet("dbx-results-pane-size", String(resultsPane.size));}}-let queryRunningElapsedTimer: ReturnType<typeof setInterval> | undefined;+let queryRunningElapsedFrame: number | undefined;function stopQueryRunningElapsedTimer() {- clearInterval(queryRunningElapsedTimer);- queryRunningElapsedTimer = undefined;+ if (queryRunningElapsedFrame !== undefined) {+ window.cancelAnimationFrame(queryRunningElapsedFrame);+ queryRunningElapsedFrame = undefined;+ }}function updateQueryRunningElapsed() {@@ -392,10 +395,16 @@ function startQueryRunningElapsedTimer() {stopQueryRunningElapsedTimer();updateQueryRunningElapsed();if (!props.activeTab.isExecuting || !props.activeTab.queryExecutionStartedAt) return;- queryRunningElapsedTimer = setInterval(updateQueryRunningElapsed, 100);+ const updateOnNextFrame = () => {+ updateQueryRunningElapsed();+ if (props.activeTab.isExecuting && props.activeTab.queryExecutionStartedAt) {+ queryRunningElapsedFrame = window.requestAnimationFrame(updateOnNextFrame);+ }+ };+ queryRunningElapsedFrame = window.requestAnimationFrame(updateOnNextFrame);}-const queryRunningElapsedSeconds = computed(() => (queryRunningElapsed.value / 1000).toFixed(1));+const queryRunningElapsedSeconds = computed(() => formatElapsedSeconds(queryRunningElapsed.value));watch(() => [props.activeTab.id, props.activeTab.isExecuting, props.activeTab.queryExecutionStartedAt] as const, startQueryRunningElapsedTimer, { immediate: true });diff --git a/apps/desktop/src/lib/__tests__/common/elapsedTime.spec.ts b/apps/desktop/src/lib/__tests__/common/elapsedTime.spec.tsnew file mode 100644index 0000000000..e6e648829c--- /dev/null+++ b/apps/desktop/src/lib/__tests__/common/elapsedTime.spec.ts@@ -0,0 +1,15 @@+import { describe, expect, it } from "vitest";+import { formatElapsedSeconds } from "@/lib/common/elapsedTime";++describe("formatElapsedSeconds", () => {+ it("formats elapsed milliseconds with two fractional second digits", () => {+ expect(formatElapsedSeconds(1234)).toBe("1.23");+ expect(formatElapsedSeconds(5)).toBe("0.01");+ expect(formatElapsedSeconds(0)).toBe("0.00");+ });++ it("clamps invalid elapsed values to zero", () => {+ expect(formatElapsedSeconds(-100)).toBe("0.00");+ expect(formatElapsedSeconds(Number.NaN)).toBe("0.00");+ });+});diff --git a/apps/desktop/src/lib/common/elapsedTime.ts b/apps/desktop/src/lib/common/elapsedTime.tsnew file mode 100644index 0000000000..e814a7bba8--- /dev/null+++ b/apps/desktop/src/lib/common/elapsedTime.ts@@ -0,0 +1,3 @@+export function formatElapsedSeconds(ms: number): string {+ return (Math.max(0, Number.isFinite(ms) ? ms : 0) / 1000).toFixed(2);+}