Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore(frontend): performance optimization (#12696)

Liu Ji65edd6a35695
diff --git a/frontend/src/Splash.vue b/frontend/src/Splash.vue
new file mode 100644
index 0000000000..b7439254f9
--- /dev/null
+++ b/frontend/src/Splash.vue
@@ -0,0 +1,33 @@
+<template>
+ <NConfigProvider
+ :locale="generalLang"
+ :date-locale="dateLang"
+ :theme-overrides="themeOverrides"
+ >
+ <NNotificationProvider
+ :max="MAX_NOTIFICATION_DISPLAY_COUNT"
+ placement="bottom-right"
+ >
+ <NDialogProvider>
+ <NotificationContext>
+ <div class="fixed inset-0 bg-white flex flex-col items-center justify-center">
+ <NSpin />
+ </div>
+ </NotificationContext>
+ </NDialogProvider>
+ </NNotificationProvider>
+ </NConfigProvider>
+</template>
+
+<script lang="ts" setup>
+import {
+ NConfigProvider,
+ NDialogProvider,
+ NNotificationProvider,
+ NSpin,
+} from "naive-ui";
+import { themeOverrides, dateLang, generalLang } from "../naive-ui.config";
+import NotificationContext from "./NotificationContext.vue";
+
+const MAX_NOTIFICATION_DISPLAY_COUNT = 3;
+</script>
diff --git a/frontend/src/components/Project/useProjectSidebar.ts b/frontend/src/components/Project/useProjectSidebar.ts
index 3b05029e28..3f8adbc52d 100644
--- a/frontend/src/components/Project/useProjectSidebar.ts
+++ b/frontend/src/components/Project/useProjectSidebar.ts
@@ -11,9 +11,11 @@ import {
SearchCodeIcon,
DownloadIcon,
} from "lucide-vue-next";
-import { computed, h } from "vue";
-import type { Ref } from "vue";
-import type { RouteRecordRaw } from "vue-router";
+import { computed, h, unref } from "vue";
+import type {
+ RouteLocationNormalizedLoadedGeneric,
+ RouteRecordRaw,
+} from "vue-router";
import { useRoute } from "vue-router";
import type { SidebarItem } from "@/components/CommonSidebar.vue";
import { t } from "@/plugins/i18n";
@@ -38,7 +40,7 @@ import projectV1Routes, {
PROJECT_V1_ROUTE_REVIEW_CENTER,
} from "@/router/dashboard/projectV1";
import { useCurrentUserV1 } from "@/store";
-import type { ComposedProject } from "@/types";
+import type { ComposedProject, MaybeRef } from "@/types";
import { DEFAULT_PROJECT_V1_NAME } from "@/types";
import type { ProjectPermission } from "@/types";
import { hasProjectPermissionV2 } from "@/utils";
@@ -50,12 +52,15 @@ interface ProjectSidebarItem extends SidebarItem {
children?: ProjectSidebarItem[];
}
-export const useProjectSidebar = (project: Ref<ComposedProject>) => {
+export const useProjectSidebar = (
+ project: MaybeRef<ComposedProject>,
+ _route?: RouteLocationNormalizedLoadedGeneric
+) => {
const currentUser = useCurrentUserV1();
- const route = useRoute();
+ const route = _route ?? useRoute();
const isDefaultProject = computed((): boolean => {
- return project.value.name === DEFAULT_PROJECT_V1_NAME;
+ return unref(project).name === DEFAULT_PROJECT_V1_NAME;
});
const getFlattenProjectV1Routes = (
@@ -109,7 +114,7 @@ export const useProjectSidebar = (project: Ref<ComposedProject>) => {
(projectV1Route) => projectV1Route.name === item.path
);
return (routeConfig?.permissions ?? []).every((permission) =>
- hasProjectPermissionV2(project.value, currentUser.value, permission)
+ hasProjectPermissionV2(unref(project), currentUser.value, permission)
);
})
.map((item) => ({
diff --git a/frontend/src/components/ProvideDashboardContext.vue b/frontend/src/components/ProvideDashboardContext.vue
index 90095752b1..add68ab4d4 100644
--- a/frontend/src/components/ProvideDashboardContext.vue
+++ b/frontend/src/components/ProvideDashboardContext.vue
@@ -1,5 +1,6 @@
<template>
<slot v-if="!isLoading" />
+ <MaskSpinner v-else class="!bg-white" />
</template>
<script lang="ts" setup>
@@ -19,6 +20,7 @@ import {
} from "@/store";
import { projectNamePrefix } from "@/store/modules/v1/common";
import { PolicyResourceType } from "@/types/proto/v1/org_policy_service";
+import MaskSpinner from "./misc/MaskSpinner.vue";
const route = useRoute();
const router = useRouter();
diff --git a/frontend/src/components/v2/Model/ProjectV1Table.vue b/frontend/src/components/v2/Model/ProjectV1Table.vue
index 5e82ea8d06..3cd7ca3c4a 100644
--- a/frontend/src/components/v2/Model/ProjectV1Table.vue
+++ b/frontend/src/components/v2/Model/ProjectV1Table.vue
@@ -117,7 +117,8 @@ const rowProps = (project: ComposedProject) => {
routeName = activeSidebar.value?.path ?? routeName;
const { flattenNavigationItems } = useProjectSidebar(
- computed(() => project)
+ project,
+ router.currentRoute.value
);
if (
!flattenNavigationItems.value.find(
diff --git a/frontend/src/main.ts b/frontend/src/main.ts
index a8e5568519..7efde5a178 100644
--- a/frontend/src/main.ts
+++ b/frontend/src/main.ts
@@ -4,6 +4,7 @@ import Long from "long";
import protobufjs from "protobufjs";
import { createApp } from "vue";
import App from "./App.vue";
+import Splash from "./Splash.vue";
import "./assets/css/github-markdown-style.css";
import "./assets/css/inter.css";
import "./assets/css/tailwind.css";
@@ -194,7 +195,12 @@ const initBasicModules = async () => {
]);
};
+const splash = createApp(Splash);
+splash.use(pinia).use(i18n).use(NaiveUI).mount("#app");
+
initBasicModules().finally(() => {
+ splash.unmount();
+
// Install router after the necessary data fetching is complete.
app.use(router).use(highlight).use(i18n).use(NaiveUI);
app.mount("#app");
diff --git a/frontend/src/store/modules/v1/database.ts b/frontend/src/store/modules/v1/database.ts
index e1335e66f3..a1cf3b519e 100644
--- a/frontend/src/store/modules/v1/database.ts
+++ b/frontend/src/store/modules/v1/database.ts
@@ -1,6 +1,6 @@
import { uniq } from "lodash-es";
import { defineStore } from "pinia";
-import { computed, reactive, ref, unref, watch } from "vue";
+import { computed, reactive, ref, unref, watch, markRaw } from "vue";
import { databaseServiceClient } from "@/grpcweb";
import type { ComposedInstance, ComposedDatabase, MaybeRef } from "@/types";
import {
@@ -343,6 +343,6 @@ export const batchComposeDatabase = async (databaseList: Database[]) => {
composed.effectiveEnvironmentEntity =
environmentV1Store.getEnvironmentByName(db.effectiveEnvironment) ??
unknownEnvironment();
- return composed;
+ return markRaw(composed);
});
};
diff --git a/frontend/src/views/DatabaseDashboard.vue b/frontend/src/views/DatabaseDashboard.vue
index 8872fe944c..e896c0c514 100644
--- a/frontend/src/views/DatabaseDashboard.vue
+++ b/frontend/src/views/DatabaseDashboard.vue
@@ -157,8 +157,9 @@ onMounted(() => {
});
const databaseV1List = computed(() => {
+ const projects = new Set(projectList.value.map((project) => project.name));
return sortDatabaseV1List(databaseV1Store.databaseList).filter((db) =>
- projectList.value.map((project) => project.name).includes(db.project)
+ projects.has(db.project)
);
});