fix(desktop): format loading elapsed time
This commit is contained in:
1 parent
6b13564180
commit
8883a6b3b7
4 files changed
+45
-12
No files matched your search
@@ -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>
|
||||
|
||||
@@ -67,6 +67,7 @@ import { buildMongoUpdateDocument, formatMongoShellLiteral, type MongoInputValue
|
||||
import 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 });
|
||||
|
||||
|
||||
Reference in new issue
Block a user