Skip to content

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

perf: lazy load for selectors (#18238)

ecmadao5595a6e4b333
diff --git a/frontend/src/components/Member/MembersBindingSelect.vue b/frontend/src/components/Member/MembersBindingSelect.vue
index a46a8ce76a..5db7c40bc9 100644
--- a/frontend/src/components/Member/MembersBindingSelect.vue
+++ b/frontend/src/components/Member/MembersBindingSelect.vue
@@ -74,15 +74,10 @@
<script setup lang="ts">
import { uniq } from "lodash-es";
import { NRadio, NRadioGroup } from "naive-ui";
-import { computed, ref, watchEffect } from "vue";
+import { computed, ref } from "vue";
import RequiredStar from "@/components/RequiredStar.vue";
import { GroupSelect, UserSelect } from "@/components/v2";
-import {
- extractGroupEmail,
- extractUserId,
- useGroupStore,
- useUserStore,
-} from "@/store";
+import { extractGroupEmail, extractUserId, useGroupStore } from "@/store";
import { groupNamePrefix } from "@/store/modules/v1/common";
import {
getGroupEmailInBinding,
@@ -118,17 +113,8 @@ const emit = defineEmits<{
}>();
const memberType = ref<MemberType>("USERS");
-const userStore = useUserStore();
const groupStore = useGroupStore();
-watchEffect(async () => {
- await userStore.batchGetUsers(
- props.value.map((binding) =>
- binding.startsWith(groupBindingPrefix) ? "" : binding
- )
- );
-});
-
const onTypeChange = (type: MemberType) => {
emit("update:value", []);
memberType.value = type;
@@ -145,11 +131,11 @@ const memberList = computed(() => {
}
list.push(group.name);
} else {
- const user = userStore.getUserByIdentifier(binding);
- if (!user) {
- continue;
+ // For users, extract email from binding format "user:{email}"
+ const email = extractUserId(binding);
+ if (email) {
+ list.push(email);
}
- list.push(extractUserId(user.name));
}
}
@@ -163,11 +149,8 @@ const onMemberListUpdate = (memberList: string[]) => {
const email = extractGroupEmail(member);
return getGroupEmailInBinding(email);
}
- const user = userStore.getUserByIdentifier(member);
- if (!user) {
- return "";
- }
- return getUserEmailInBinding(user.email);
+ // UserSelect now returns email directly
+ return getUserEmailInBinding(member);
})
.filter((binding) => binding);
diff --git a/frontend/src/components/User/Settings/CreateGroupDrawer.vue b/frontend/src/components/User/Settings/CreateGroupDrawer.vue
index 568221d7d0..245d7b1b65 100644
--- a/frontend/src/components/User/Settings/CreateGroupDrawer.vue
+++ b/frontend/src/components/User/Settings/CreateGroupDrawer.vue
@@ -54,11 +54,11 @@
<div class="flex flex-col gap-y-2">
<div
v-for="(member, i) in state.group.members"
- :key="member.member"
+ :key="i"
class="w-full flex items-center gap-x-3"
>
<UserSelect
- :user="getUserUidForMember(member)"
+ :user="extractUserId(member.member)"
:multiple="false"
:size="'medium'"
:include-all="false"
@@ -70,7 +70,7 @@
member.member === `${userNamePrefix}${user.email}`
)
"
- @update:user="(uid) => updateMemberEmail(i, uid)"
+ @update:user="(email) => updateMemberEmail(i, email)"
/>
<GroupMemberRoleSelect
:value="member.role"
@@ -150,17 +150,12 @@ import { create } from "@bufbuild/protobuf";
import { cloneDeep, isEqual } from "lodash-es";
import { Trash2Icon } from "lucide-vue-next";
import { NButton, NInput, NTooltip } from "naive-ui";
-import { computed, reactive, watchEffect } from "vue";
+import { computed, reactive } from "vue";
import { useI18n } from "vue-i18n";
import EmailInput from "@/components/EmailInput.vue";
import RequiredStar from "@/components/RequiredStar.vue";
import { Drawer, DrawerContent, UserSelect } from "@/components/v2";
-import {
- pushNotification,
- useCurrentUserV1,
- useGroupStore,
- useUserStore,
-} from "@/store";
+import { pushNotification, useCurrentUserV1, useGroupStore } from "@/store";
import {
extractUserId,
groupNamePrefix,
@@ -196,7 +191,6 @@ const emit = defineEmits<{
}>();
const { t } = useI18n();
-const userStore = useUserStore();
const groupStore = useGroupStore();
const currentUserV1 = useCurrentUserV1();
@@ -219,13 +213,6 @@ const state = reactive<LocalState>({
const isCreating = computed(() => !props.group);
-watchEffect(async () => {
- if (props.group) {
- const memberUserIds = props.group.members.map((m) => m.member);
- await userStore.batchGetUsers(memberUserIds);
- }
-});
-
const isGroupOwner = computed(() => {
return (
props.group?.members.find(
@@ -302,28 +289,13 @@ const addMember = () => {
state.group.members.push(member);
};
-const getUserUidForMember = (member: GroupMember) => {
- if (!member.member) {
- return;
- }
- const user = userStore.getUserByIdentifier(member.member);
- if (!user) {
- return;
- }
- return extractUserId(user.name);
-};
-
-const updateMemberEmail = (index: number, uid: string | undefined) => {
- if (!uid) {
- return;
- }
- const user = userStore.getUserByIdentifier(uid);
- if (!user) {
+const updateMemberEmail = (index: number, email: string | undefined) => {
+ if (!email) {
return;
}
state.group.members[index] = {
...state.group.members[index],
- member: `${userNamePrefix}${user.email}`,
+ member: `${userNamePrefix}${email}`,
};
};
diff --git a/frontend/src/components/v2/Select/DatabaseSelect.vue b/frontend/src/components/v2/Select/DatabaseSelect.vue
index 8896d11ec9..d4756e53bf 100644
--- a/frontend/src/components/v2/Select/DatabaseSelect.vue
+++ b/frontend/src/components/v2/Select/DatabaseSelect.vue
@@ -18,7 +18,7 @@
<script lang="ts" setup>
import { useDebounceFn } from "@vueuse/core";
-import { computed, h, reactive, watch, watchEffect } from "vue";
+import { computed, h, reactive, watch } from "vue";
import { useI18n } from "vue-i18n";
import { useDatabaseV1Store } from "@/store";
import { workspaceNamePrefix } from "@/store/modules/v1/common";
@@ -40,6 +40,8 @@ import ResourceSelect from "./ResourceSelect.vue";
interface LocalState {
loading: boolean;
rawDatabaseList: ComposedDatabase[];
+ // Track if initial fetch has been done to avoid redundant API calls
+ initialized: boolean;
}
const props = withDefaults(
@@ -80,8 +82,9 @@ const { t } = useI18n();
const databaseStore = useDatabaseV1Store();
const state = reactive<LocalState>({
- loading: true,
+ loading: false,
rawDatabaseList: [],
+ initialized: false,
});
const initSelectedDatabases = async (databaseNames: string[]) => {
@@ -108,35 +111,52 @@ const searchDatabases = async (name: string) => {
return databases;
};
+const initDatabaseList = async () => {
+ if (props.includeAll) {
+ const dummyAll = {
+ ...unknownDatabase(),
+ databaseName: t("database.all"),
+ };
+ if (!state.rawDatabaseList.find((d) => d.name === dummyAll.name)) {
+ state.rawDatabaseList.unshift(dummyAll);
+ }
+ }
+ if (props.databaseName) {
+ await initSelectedDatabases([props.databaseName]);
+ }
+ if (props.databaseNames) {
+ await initSelectedDatabases(props.databaseNames);
+ }
+};
+
const handleSearch = useDebounceFn(async (search: string) => {
+ // Skip if no search term and already initialized (lazy loading optimization)
+ if (!search && state.initialized) {
+ return;
+ }
+
state.loading = true;
try {
const databases = await searchDatabases(search);
state.rawDatabaseList = databases;
if (!search) {
- if (props.includeAll) {
- const dummyAll = {
- ...unknownDatabase(),
- databaseName: t("database.all"),
- };
- state.rawDatabaseList.unshift(dummyAll);
- }
- if (props.databaseName) {
- await initSelectedDatabases([props.databaseName]);
- }
- if (props.databaseNames) {
- await initSelectedDatabases(props.databaseNames);
- }
+ state.initialized = true;
+ await initDatabaseList();
}
} finally {
state.loading = false;
}
}, DEBOUNCE_SEARCH_DELAY);
+// Only fetch selected database(s) on mount, not the entire list.
+// The full list will be fetched lazily when dropdown is opened.
+// Re-initialize when filter props change.
watch(
() => [props.environmentName, props.allowedEngineTypeList],
() => {
- handleSearch("");
+ state.initialized = false;
+ state.rawDatabaseList = [];
+ initDatabaseList();
},
{
deep: true,
@@ -162,16 +182,20 @@ const options = computed(() => {
});
});
-watchEffect(() => {
- if (!props.defaultSelectFirst || props.multiple) {
- return;
- }
- if (options.value.length === 0) {
- return;
- }
+watch(
+ () => options.value,
+ () => {
+ if (!props.defaultSelectFirst || props.multiple) {
+ return;
+ }
+ if (options.value.length === 0) {
+ return;
+ }
- emit("update:database-name", options.value[0].value);
-});
+ emit("update:database-name", options.value[0].value);
+ },
+ { immediate: true }
+);
const renderLabel = (database: ComposedDatabase) => {
const children = [h("div", {}, [database.databaseName])];
@@ -208,8 +232,10 @@ const renderLabel = (database: ComposedDatabase) => {
// and emit the event.
const resetInvalidSelection = () => {
if (!props.autoReset || props.multiple) return;
+ if (state.loading) return;
+ // Don't reset selection before the full database list has been fetched
+ if (!state.initialized) return;
if (
- !state.loading &&
props.databaseName &&
!combinedDatabaseList.value.find((item) => item.name === props.databaseName)
) {
diff --git a/frontend/src/components/v2/Select/GroupSelect.vue b/frontend/src/components/v2/Select/GroupSelect.vue
index 2f78590651..d25df6536b 100644
--- a/frontend/src/components/v2/Select/GroupSelect.vue
+++ b/frontend/src/components/v2/Select/GroupSelect.vue
@@ -53,11 +53,14 @@ defineEmits<{
interface LocalState {
loading: boolean;
rawList: Group[];
+ // Track if initial fetch has been done to avoid redundant API calls
+ initialized: boolean;
}
const state = reactive<LocalState>({
loading: false,
rawList: [],
+ initialized: false,
});
const groupStore = useGroupStore();
@@ -73,12 +76,28 @@ const searchGroups = async (search: string) => {
return groups;
};
+const initSelectedGroups = async (groupNames: string[]) => {
+ if (groupNames.length === 0) return;
+ const groups = await groupStore.batchFetchGroups(groupNames);
+ for (const group of groups) {
+ if (!state.rawList.find((g) => g.name === group.name)) {
+ state.rawList.unshift(group);
+ }
+ }
+};
+
const handleSearch = useDebounceFn(async (search: string) => {
+ // Skip if no search term and already initialized (lazy loading optimization)
+ if (!search && state.initialized) {
+ return;
+ }
+
state.loading = true;
try {
const groups = await searchGroups(search);
state.rawList = groups;
if (!search) {
+ state.initialized = true;
if (props.group) {
await initSelectedGroups([props.group]);
}
@@ -91,17 +110,14 @@ const handleSearch = useDebounceFn(async (search: string) => {
}
}, DEBOUNCE_SEARCH_DELAY);
-const initSelectedGroups = async (groupNames: string[]) => {
- const groups = await groupStore.batchFetchGroups(groupNames);
- for (const group of groups) {
- if (!state.rawList.find((g) => g.name === group.name)) {
- state.rawList.unshift(group);
- }
- }
-};
-
+// Only fetch selected group(s) on mount, not the entire list.
+// The full list will be fetched lazily when dropdown is opened.
onMounted(async () => {
- await handleSearch("");
+ if (props.group) {
+ await initSelectedGroups([props.group]);
+ } else if (props.groups) {
+ await initSelectedGroups(props.groups);
+ }
});
const options = computed(() => {
diff --git a/frontend/src/components/v2/Select/InstanceSelect.vue b/frontend/src/components/v2/Select/InstanceSelect.vue
index 7423eed9e6..cc98d4a5b4 100644
--- a/frontend/src/components/v2/Select/InstanceSelect.vue
+++ b/frontend/src/components/v2/Select/InstanceSelect.vue
@@ -36,6 +36,8 @@ import ResourceSelect from "./ResourceSelect.vue";
interface LocalState {
loading: boolean;
rawInstanceList: Instance[];
+ // Track if initial fetch has been done to avoid redundant API calls
+ initialized: boolean;
}
const props = withDefaults(
@@ -61,8 +63,9 @@ const emit = defineEmits<{
const { t } = useI18n();
const instanceStore = useInstanceV1Store();
const state = reactive<LocalState>({
- loading: true,
+ loading: false,
rawInstanceList: [],
+ initialized: false,
});
const initSelectedInstance = async (instanceName: string) => {
@@ -87,27 +90,42 @@ const searchInstances = async (name: string) => {
return instances;
};
+const initInstanceList = async () => {
+ if (props.instanceName === UNKNOWN_INSTANCE_NAME) {
+ const dummyAll = {
+ ...unknownInstance(),
+ title: t("instance.all"),
+ };
+ if (!state.rawInstanceList.find((ins) => ins.name === dummyAll.name)) {
+ state.rawInstanceList.unshift(dummyAll);
+ }
+ } else if (props.instanceName) {
+ await initSelectedInstance(props.instanceName);
+ }
+};
+
const handleSearch = useDebounceFn(async (search: string) => {
+ // Skip if no search term and already initialized (lazy loading optimization)
+ if (!search && state.initialized) {
+ return;
+ }
+
state.loading = true;
try {
const instances = await searchInstances(search);
state.rawInstanceList = instances;
if (!search) {
- if (props.instanceName === UNKNOWN_INSTANCE_NAME) {
- const dummyAll = {
- ...unknownInstance(),
- title: t("instance.all"),
- };
- state.rawInstanceList.unshift(dummyAll);
- } else if (props.instanceName) {
- await initSelectedInstance(props.instanceName);
- }
+ state.initialized = true;
+ await initInstanceList();
}
} finally {
state.loading = false;
}
}, DEBOUNCE_SEARCH_DELAY);
+// Only fetch selected instance on mount, not the entire list.
+// The full list will be fetched lazily when dropdown is opened.
+// Re-initialize when filter props change.
watch(
[
() => props.allowedEngineList,
@@ -115,7 +133,9 @@ watch(
() => props.projectName,
],
() => {
- handleSearch("");
+ state.initialized = false;
+ state.rawInstanceList = [];
+ initInstanceList();
},
{
immediate: true,
@@ -160,6 +180,10 @@ const resetInvalidSelection = () => {
if (state.loading) {
return;
}
+ // Don't reset selection before the full instance list has been fetched
+ if (!state.initialized) {
+ return;
+ }
if (
props.instanceName &&
!state.rawInstanceList.find((item) => item.name === props.instanceName)
diff --git a/frontend/src/components/v2/Select/ProjectSelect.vue b/frontend/src/components/v2/Select/ProjectSelect.vue
index 8cf96323f9..7086aabf07 100644
--- a/frontend/src/components/v2/Select/ProjectSelect.vue
+++ b/frontend/src/components/v2/Select/ProjectSelect.vue
@@ -75,14 +75,17 @@ const emit = defineEmits<{
interface LocalState {
loading: boolean;
rawProjectList: Project[];
+ // Track if initial fetch has been done to avoid redundant API calls
+ initialized: boolean;
}
const { t } = useI18n();
const permissionStore = usePermissionStore();
const projectStore = useProjectV1Store();
const state = reactive<LocalState>({
- loading: true,
+ loading: false,
rawProjectList: [],
+ initialized: false,
});
const initSelectedProjects = async (projectNames: string[]) => {
@@ -150,6 +153,11 @@ const combinedProjectList = computed(() => {
});
const handleSearch = useDebounceFn(async (search: string) => {
+ // Skip if no search term and already initialized (lazy loading optimization)
+ if (!search && state.initialized) {
+ return;
+ }
+
state.loading = true;
try {
const { projects } = await projectStore.fetchProjectList({
@@ -161,6 +169,7 @@ const handleSearch = useDebounceFn(async (search: string) => {
});
state.rawProjectList = projects;
if (!search) {
+ state.initialized = true;
await initProjectList();
}
} finally {
@@ -168,8 +177,10 @@ const handleSearch = useDebounceFn(async (search: string) => {
}
}, DEBOUNCE_SEARCH_DELAY);
+// Only fetch selected project(s) on mount, not the entire list.
+// The full list will be fetched lazily when dropdown is opened.
onMounted(async () => {
- await handleSearch("");
+ await initProjectList();
});
const options = computed(
diff --git a/frontend/src/components/v2/Select/UserSelect.vue b/frontend/src/components/v2/Select/UserSelect.vue
index 81cba9f3f2..15784e079a 100644
--- a/frontend/src/components/v2/Select/UserSelect.vue
+++ b/frontend/src/components/v2/Select/UserSelect.vue
@@ -22,7 +22,7 @@
import { useDebounceFn } from "@vueuse/core";
import { computed, onMounted, reactive, watch } from "vue";
import { UserNameCell } from "@/components/v2/Model/cells";
-import { extractUserId, type UserFilter, useUserStore } from "@/store";
+import { type UserFilter, useUserStore } from "@/store";
import { allUsersUser, DEBOUNCE_SEARCH_DELAY, isValidUserName } from "@/types";
import { type User, UserType } from "@/types/proto-es/v1/user_service_pb";
import { ensureUserFullName, getDefaultPagination } from "@/utils";
@@ -64,12 +64,15 @@ const emit = defineEmits<{
interface LocalState {
loading: boolean;
rawUserList: User[];
+ // Track if initial fetch has been done to avoid redundant API calls
+ initialized: boolean;
}
const userStore = useUserStore();
const state = reactive<LocalState>({
loading: false,
rawUserList: [],
+ initialized: false,
});
const getFilter = (search: string): UserFilter => {
@@ -92,9 +95,10 @@ const getFilter = (search: string): UserFilter => {
};
};
-const initSelectedUsers = async (userIds: string[]) => {
- for (const userId of userIds) {
- const userName = ensureUserFullName(userId);
+const initSelectedUsers = async (userEmails: string[]) => {
+ for (const email of userEmails) {
+ if (!email) continue;
+ const userName = ensureUserFullName(email);
if (isValidUserName(userName)) {
const user = await userStore.getOrFetchUserByIdentifier(userName);
if (!state.rawUserList.find((u) => u.name === user.name)) {
@@ -113,11 +117,17 @@ const searchUsers = async (search: string) => {
};
const handleSearch = useDebounceFn(async (search: string) => {
+ // Skip if no search term and already initialized (lazy loading optimization)
+ if (!search && state.initialized) {
+ return;
+ }
+
state.loading = true;
try {
const users = await searchUsers(search);
state.rawUserList = users;
if (!search) {
+ state.initialized = true;
if (props.includeAllUsers) {
state.rawUserList.unshift(allUsersUser());
}
@@ -133,8 +143,16 @@ const handleSearch = useDebounceFn(async (search: string) => {
}
}, DEBOUNCE_SEARCH_DELAY);
+// Only fetch the selected user(s) on mount, not the entire user list.
+// The full list will be fetched lazily when dropdown is opened.
onMounted(async () => {
- await handleSearch("");
+ let users: string[] = [];
+ if (props.user) {
+ users = [props.user];
+ } else if (props.users) {
+ users = props.users;
+ }
+ await initSelectedUsers(users);
});
const renderLabel = (user: User) => {
@@ -159,7 +177,7 @@ const options = computed(() => {
return state.rawUserList.map((user) => {
return {
resource: user,
- value: extractUserId(user.name),
+ value: user.email,
label: user.title,
};
});
@@ -179,9 +197,13 @@ const resetInvalidSelection = () => {
if (state.loading) {
return;
}
+ // Don't reset selection before the full user list has been fetched
+ if (!state.initialized) {
+ return;
+ }
if (
props.user &&
- !state.rawUserList.find((user) => extractUserId(user.name) === props.user)
+ !state.rawUserList.find((user) => user.email === props.user)
) {
emit("update:user", undefined);
}