Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore(frontend): schema editor speed-up and loading indicators (#9433)
Liu Ji39a962792e5c
diff --git a/frontend/src/components/Branch/BranchCreateView.vue b/frontend/src/components/Branch/BranchCreateView.vueindex 6c698b7b19..73b254455a 100644--- a/frontend/src/components/Branch/BranchCreateView.vue+++ b/frontend/src/components/Branch/BranchCreateView.vue@@ -54,6 +54,7 @@<div class="w-full flex-1 overflow-y-hidden"><SchemaEditorV1:key="refreshId"+ :loading="state.loading":project="project":resource-type="'branch'":branches="branches"@@ -122,6 +123,7 @@ interface BaselineSchema {interface LocalState {projectId?: string;+ loading: boolean;baselineSchema: BaselineSchema;schemaDesign: SchemaDesign;parentBranchName?: string;@@ -144,6 +146,7 @@ const changeHistoryStore = useChangeHistoryStore();const sheetStore = useSheetV1Store();const state = reactive<LocalState>({projectId: props.projectId,+ loading: false,baselineSchema: {},schemaDesign: SchemaDesign.fromPartial({type: SchemaDesign_Type.MAIN_BRANCH,@@ -302,7 +305,11 @@ const handleBaselineSchemaChange = async (baselineSchema: BaselineSchema) => {const database = databaseStore.getDatabaseByUID(baselineSchema.databaseId);state.projectId = database.projectEntity.uid;}+ console.time("prepareSchemaDesign");+ state.loading = true;state.schemaDesign = await prepareSchemaDesign();+ state.loading = false;+ console.timeEnd("prepareSchemaDesign");};const handleConfirm = async () => {diff --git a/frontend/src/components/DatabaseDetail/SQLEditorButtonV1.vue b/frontend/src/components/DatabaseDetail/SQLEditorButtonV1.vueindex b3337a8110..77683daf1f 100644--- a/frontend/src/components/DatabaseDetail/SQLEditorButtonV1.vue+++ b/frontend/src/components/DatabaseDetail/SQLEditorButtonV1.vue@@ -37,7 +37,7 @@ import {DEFAULT_PROJECT_V1_NAME,UNKNOWN_PROJECT_NAME,} from "@/types";-import { connectionV1Slug, hasWorkspacePermissionV1 } from "@/utils";+import { VueClass, connectionV1Slug, hasWorkspacePermissionV1 } from "@/utils";interface LocalState {showRequestQueryPanel: boolean;@@ -49,12 +49,14 @@ const props = withDefaults(label?: boolean;disabled?: boolean;tooltip?: boolean;+ class?: VueClass;}>(),{database: undefined,label: false,disabled: false,tooltip: false,+ class: undefined,});@@ -74,7 +76,7 @@ const showTooltip = computed((): boolean => {return !props.disabled && props.tooltip;});-const classes = computed((): string[] => {+const classes = computed(() => {const classes: string[] = [];if (showTooltip.value) {classes.push("tooltip-wrapper");@@ -84,7 +86,7 @@ const classes = computed((): string[] => {} else {classes.push("textlabel", "cursor-pointer", "hover:text-accent");}- return classes;+ return [...classes, props.class];});const gotoSQLEditor = () => {diff --git a/frontend/src/components/SchemaEditorV1/Aside/BranchTree.vue b/frontend/src/components/SchemaEditorV1/Aside/BranchTree.vueindex 79417c7850..13fcd0e578 100644--- a/frontend/src/components/SchemaEditorV1/Aside/BranchTree.vue+++ b/frontend/src/components/SchemaEditorV1/Aside/BranchTree.vue@@ -26,6 +26,7 @@:data-height="treeContainerHeight"><NTree+ v-if="treeContainerHeight > 0":key="treeKeyRef"ref="treeRef"block-linediff --git a/frontend/src/components/SchemaEditorV1/Aside/DatabaseTree.vue b/frontend/src/components/SchemaEditorV1/Aside/DatabaseTree.vueindex e1660f96c4..f17767f7e7 100644--- a/frontend/src/components/SchemaEditorV1/Aside/DatabaseTree.vue+++ b/frontend/src/components/SchemaEditorV1/Aside/DatabaseTree.vue@@ -18,10 +18,13 @@:data-height="treeContainerHeight"><NTree+ v-if="treeContainerHeight > 0"ref="treeRef"block-linevirtual-scroll- style="height: 100%"+ :style="{+ height: `${treeContainerHeight}px`,+ }":data="treeDataRef":pattern="searchPattern":render-prefix="renderPrefix"diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/TableColumnEditor.vue b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/TableColumnEditor.vueindex f7a667424f..97bb74fdeb 100644--- a/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/TableColumnEditor.vue+++ b/frontend/src/components/SchemaEditorV1/Panels/TableColumnEditor/TableColumnEditor.vue@@ -11,11 +11,13 @@size="small":row-key="(column: Column) => column.id":columns="columns"- :data="shownColumnList"+ :data="layoutReady ? shownColumnList : []":row-class-name="classesForRow":max-height="tableBodyHeight":virtual-scroll="true":striped="true"+ :bordered="true"+ :bottom-bordered="true"class="schema-editor-table-column-editor"/></div>@@ -147,6 +149,8 @@ const { height: tableHeaderHeight } = useElementSize(tableHeaderElRef);const tableBodyHeight = computed(() => {return containerHeight.value - tableHeaderHeight.value - 2;});+// Use this to avoid unnecessary initial rendering+const layoutReady = computed(() => tableHeaderHeight.value > 0);const { t } = useI18n();const subscriptionV1Store = useSubscriptionV1Store();const settingStore = useSettingV1Store();diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableList/TableList.vue b/frontend/src/components/SchemaEditorV1/Panels/TableList/TableList.vueindex 1a93c476c5..bcda9ca219 100644--- a/frontend/src/components/SchemaEditorV1/Panels/TableList/TableList.vue+++ b/frontend/src/components/SchemaEditorV1/Panels/TableList/TableList.vue@@ -11,7 +11,7 @@size="small":row-key="(table: Table) => table.id":columns="columns"- :data="tableList"+ :data="layoutReady ? tableList : []":row-class-name="classesForRow":max-height="tableBodyHeight":virtual-scroll="true"@@ -117,6 +117,8 @@ const { height: tableHeaderHeight } = useElementSize(tableHeaderElRef);const tableBodyHeight = computed(() => {return containerHeight.value - tableHeaderHeight.value - 2;});+// Use this to avoid unnecessary initial rendering+const layoutReady = computed(() => tableHeaderHeight.value > 0);const editorStore = useSchemaEditorV1Store();const settingStore = useSettingV1Store();const currentTab = computed(@@ -230,6 +232,7 @@ const columns = computed(() => {resizable: true,width: 120,ellipsis: true,+ ellipsisComponent: "performant-ellipsis",},{key: "comment",@@ -237,6 +240,7 @@ const columns = computed(() => {resizable: true,width: 140,ellipsis: true,+ ellipsisComponent: "performant-ellipsis",},{key: "operations",@@ -268,6 +272,7 @@ const classesForRow = (table: Table, index: number) => {) {return "updated";}+ return "";};const handleTableItemClick = (table: Table) => {diff --git a/frontend/src/components/SchemaEditorV1/Panels/TableList/components/NameCell.vue b/frontend/src/components/SchemaEditorV1/Panels/TableList/components/NameCell.vueindex 7b7876fe52..ca2d79e75a 100644--- a/frontend/src/components/SchemaEditorV1/Panels/TableList/components/NameCell.vue+++ b/frontend/src/components/SchemaEditorV1/Panels/TableList/components/NameCell.vue@@ -1,13 +1,15 @@<template>- <NEllipsis class="w-full cursor-pointer leading-6 hover:text-accent">+ <NPerformantEllipsis+ class="w-full cursor-pointer leading-6 hover:text-accent"+ ><span @click="$emit('click')">{{ table.name }}</span>- </NEllipsis>+ </NPerformantEllipsis></template><script lang="ts" setup>-import { NEllipsis } from "naive-ui";+import { NPerformantEllipsis } from "naive-ui";import { Table } from "@/types/v1/schemaEditor";defineProps<{diff --git a/frontend/src/components/SchemaEditorV1/index.vue b/frontend/src/components/SchemaEditorV1/index.vueindex 960d050e53..78933bcf03 100644--- a/frontend/src/components/SchemaEditorV1/index.vue+++ b/frontend/src/components/SchemaEditorV1/index.vue@@ -1,11 +1,13 @@<template><div- v-if="state.initialized"- class="w-full h-full border rounded-lg overflow-hidden"+ class="w-full h-full border rounded-lg overflow-hidden relative"v-bind="$attrs">+ <MaskSpinner v-if="mergedLoading" />+<Splitpanes- class="default-theme w-full h-full flex flex-row overflow-hidden"+ v-if="state.initialized"+ class="default-theme w-full h-full flex flex-row overflow-hidden relative"><Pane min-size="15" size="25"><Aside />@@ -20,7 +22,7 @@<script lang="ts" setup>import { isEqual } from "lodash-es";import { Splitpanes, Pane } from "splitpanes";-import { onMounted, watch, reactive } from "vue";+import { onMounted, watch, reactive, computed } from "vue";import { useSchemaEditorV1Store, useSettingV1Store } from "@/store";import { useSchemaDesignStore } from "@/store/modules/schemaDesign";import { ComposedProject, ComposedDatabase } from "@/types";@@ -29,6 +31,8 @@ import {SchemaDesign_Type,} from "@/types/proto/v1/schema_design_service";import { BranchSchema } from "@/types/v1/schemaEditor";+import { nextAnimationFrame } from "@/utils";+import MaskSpinner from "../misc/MaskSpinner.vue";import Aside from "./Aside/index.vue";import Editor from "./Editor.vue";import { convertBranchToBranchSchema } from "./utils/branch";@@ -40,9 +44,11 @@ const props = defineProps<{databases?: ComposedDatabase[];// NOTE: we only support editing one branch for now.branches?: SchemaDesign[];+ loading?: boolean;}>();interface LocalState {+ loading: boolean;initialized: boolean;}@@ -50,9 +56,14 @@ const settingStore = useSettingV1Store();const schemaEditorV1Store = useSchemaEditorV1Store();const schemaDesignStore = useSchemaDesignStore();const state = reactive<LocalState>({+ loading: false,initialized: false,});+const mergedLoading = computed(() => {+ return props.loading || state.loading;+});+const prepareBranchContext = async () => {if (props.resourceType !== "branch" || !props.branches) {return;@@ -72,11 +83,17 @@ const prepareBranchContext = async () => {};const batchConvertBranchSchemas = async (branches: SchemaDesign[]) => {- return await Promise.all(- branches.map<Promise<[string, BranchSchema]>>(async (branch) => {- return [branch.name, await convertBranchToBranchSchema(branch)];- })- );+ try {+ state.loading = true;+ await nextAnimationFrame();+ return await Promise.all(+ branches.map<Promise<[string, BranchSchema]>>(async (branch) => {+ return [branch.name, await convertBranchToBranchSchema(branch)];+ })+ );+ } finally {+ state.loading = false;+ }};const initialSchemaEditorState = async () => {diff --git a/frontend/src/components/SchemaEditorV1/utils/metadata.ts b/frontend/src/components/SchemaEditorV1/utils/metadata.tsindex 180e4f9ff8..a901940b3d 100644--- a/frontend/src/components/SchemaEditorV1/utils/metadata.ts+++ b/frontend/src/components/SchemaEditorV1/utils/metadata.ts@@ -369,7 +369,7 @@ export const rebuildEditableSchemas = (`[${schemas.map((s) => s.tables.length)}]`,`[${schemaConfigList.map((sc) => sc.tableConfigs.length)}]`,].join("--");- console.log("go!", tag);+ console.debug("go!", tag);console.time(tag);const editableSchemas = cloneDeep(originalSchemas);diff --git a/frontend/src/components/misc/MaskSpinner.vue b/frontend/src/components/misc/MaskSpinner.vuenew file mode 100644index 0000000000..863bdc3131--- /dev/null+++ b/frontend/src/components/misc/MaskSpinner.vue@@ -0,0 +1,17 @@+<template>+ <div+ v-zindexable="{ enabled: true }"+ class="absolute inset-0 bg-white/50 flex flex-col items-center justify-center"+ >+ <NSpin v-bind="spinProps" />+ </div>+</template>++<script lang="ts" setup>+import { NSpin, SpinProps } from "naive-ui";+import { zindexable as vZindexable } from "vdirs";++defineProps<{+ spinProps?: SpinProps;+}>();+</script>diff --git a/frontend/src/types/v1/schemaEditor/atomType.ts b/frontend/src/types/v1/schemaEditor/atomType.tsindex e903a2d295..5bcb8d0018 100644--- a/frontend/src/types/v1/schemaEditor/atomType.ts+++ b/frontend/src/types/v1/schemaEditor/atomType.ts@@ -8,7 +8,7 @@ import {TableConfig,SchemaConfig,} from "@/types/proto/v1/database_service";-import { isGhostTable } from "@/utils";+import { isGhostTable, keyBy } from "@/utils";type Status = "normal" | "created" | "dropped";@@ -181,22 +181,30 @@ export const convertSchemaMetadataList = (schemaMetadataList: SchemaMetadata[],schemaConfigList: SchemaConfig[]): Schema[] => {+ const tag = [+ "convertSchemaMetadataList",+ `[${schemaMetadataList.map((s) => s.tables.length)}]`,+ `[${schemaConfigList.map((sc) => sc.tableConfigs.length)}]`,+ ].join("--");+ console.debug("go!", tag);+ console.time(tag);// Compose all tables of each schema.+ console.time("loop-1");+ const schemaConfigByName = keyBy(schemaConfigList, (sc) => sc.name);const schemaList: Schema[] = schemaMetadataList.map((schemaMetadata) =>convertSchemaMetadataToSchema(schemaMetadata,"normal",- schemaConfigList.find(- (schemaConfig) => schemaConfig.name === schemaMetadata.name- )+ schemaConfigByName.get(schemaMetadata.name)));+ console.timeEnd("loop-1");+ console.time("loop-2");// Build foreign keys for schema and referenced schema.+ const schemaByName = keyBy(schemaList, (s) => s.name);for (const schemaMetadata of schemaMetadataList) {- const schema = schemaList.find(- (schema) => schema.name === schemaMetadata.name- );+ const schema = schemaByName.get(schemaMetadata.name);if (!schema) {continue;}@@ -251,6 +259,8 @@ export const convertSchemaMetadataList = (table.foreignKeyList = foreignKeyList;}}+ console.timeEnd("loop-2");+ console.timeEnd(tag);return schemaList;};diff --git a/frontend/src/utils/dom.ts b/frontend/src/utils/dom.tsindex 271bf75819..a5fa28c990 100644--- a/frontend/src/utils/dom.ts+++ b/frontend/src/utils/dom.ts@@ -103,3 +103,7 @@ export const getScrollParent = (return getScrollParent(element.parentElement);}};++export const nextAnimationFrame = () => {+ return new Promise<number>((resolve) => requestAnimationFrame(resolve));+};