Skip to content

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

fix: ensure return data for batchGetOrFetchXX (#18612)

ecmadao7694ec8a091c
diff --git a/frontend/src/store/modules/user.ts b/frontend/src/store/modules/user.ts
index 119cb08d19..9516124580 100644
--- a/frontend/src/store/modules/user.ts
+++ b/frontend/src/store/modules/user.ts
@@ -175,29 +175,28 @@ export const useUserStore = defineStore("user", () => {
};
const batchGetOrFetchUsers = async (userNameList: string[]) => {
- const distinctList = uniq(userNameList)
- .filter(
- (name) =>
- Boolean(name) &&
- (name.startsWith(userNamePrefix) ||
- name.startsWith(userBindingPrefix))
- )
- .map((name) => ensureUserFullName(name))
- .filter(
- (name) =>
- isValidUserName(name) && getUserByIdentifier(name) === undefined
- );
- if (distinctList.length === 0) {
- return [];
+ const validList = uniq(userNameList).filter(
+ (name) =>
+ Boolean(name) &&
+ (name.startsWith(userNamePrefix) || name.startsWith(userBindingPrefix))
+ );
+ const pendingFetch = validList
+ .filter((name) => {
+ return isValidUserName(name) && getUserByIdentifier(name) === undefined;
+ })
+ .map((name) => ensureUserFullName(name));
+ if (pendingFetch.length === 0) {
+ return validList.map(getUserByIdentifier);
}
+
const request = create(BatchGetUsersRequestSchema, {
- names: distinctList,
+ names: pendingFetch,
});
const response = await userServiceClientConnect.batchGetUsers(request);
for (const user of response.users) {
setUser(user);
}
- return distinctList.map((name) => getUserByIdentifier(name));
+ return validList.map((name) => getUserByIdentifier(name));
};
const getOrFetchUserByIdentifier = async (
diff --git a/frontend/src/store/modules/v1/database.ts b/frontend/src/store/modules/v1/database.ts
index 4cf6ca0760..b6488a9f74 100644
--- a/frontend/src/store/modules/v1/database.ts
+++ b/frontend/src/store/modules/v1/database.ts
@@ -309,10 +309,8 @@ export const useDatabaseV1Store = defineStore("database_v1", () => {
};
const batchGetOrFetchDatabases = async (databaseNames: string[]) => {
- const distinctDatabaseList = uniq(databaseNames).filter((databaseName) => {
- if (!databaseName || !isValidDatabaseName(databaseName)) {
- return false;
- }
+ const validDatabaseList = uniq(databaseNames).filter(isValidDatabaseName);
+ const pendingFetch = validDatabaseList.filter((databaseName) => {
if (
getDatabaseByName(databaseName) &&
isValidDatabaseName(getDatabaseByName(databaseName).name)
@@ -321,8 +319,8 @@ export const useDatabaseV1Store = defineStore("database_v1", () => {
}
return true;
});
- await batchGetDatabases(distinctDatabaseList);
- return distinctDatabaseList.map(getDatabaseByName);
+ await batchGetDatabases(pendingFetch);
+ return validDatabaseList.map(getDatabaseByName);
};
const batchUpdateDatabases = async (params: BatchUpdateDatabasesRequest) => {
diff --git a/frontend/src/store/modules/v1/group.ts b/frontend/src/store/modules/v1/group.ts
index 879d0c8a50..89f1e440b1 100644
--- a/frontend/src/store/modules/v1/group.ts
+++ b/frontend/src/store/modules/v1/group.ts
@@ -103,18 +103,16 @@ export const useGroupStore = defineStore("group", () => {
};
const batchGetOrFetchGroups = async (groupNames: string[]) => {
- const distinctGroupList = uniq(groupNames).filter((groupName) => {
- if (!groupName) {
- return false;
- }
+ const validGroupList = uniq(groupNames).filter((groupName) => !!groupName);
+ const pendingFetch = validGroupList.filter((groupName) => {
const group = getGroupByIdentifier(groupName);
if (group) {
return false;
}
return true;
});
- await batchFetchGroups(distinctGroupList);
- return distinctGroupList.map(getGroupByIdentifier);
+ await batchFetchGroups(pendingFetch);
+ return validGroupList.map(getGroupByIdentifier);
};
const getOrFetchGroupByIdentifier = async (id: string) => {
diff --git a/frontend/src/store/modules/v1/project.ts b/frontend/src/store/modules/v1/project.ts
index f4cb22018d..4e9a2cf568 100644
--- a/frontend/src/store/modules/v1/project.ts
+++ b/frontend/src/store/modules/v1/project.ts
@@ -201,7 +201,7 @@ export const useProjectV1Store = defineStore("project_v1", () => {
};
const batchGetOrFetchProjects = async (projectNames: string[]) => {
- const distinctProjectList = uniq(projectNames).filter((projectName) => {
+ const validProjectList = uniq(projectNames).filter((projectName) => {
if (
!projectName ||
!isValidProjectName(projectName) ||
@@ -209,14 +209,17 @@ export const useProjectV1Store = defineStore("project_v1", () => {
) {
return false;
}
+ return true;
+ });
+ const pendingFetch = validProjectList.filter((projectName) => {
const project = getProjectByName(projectName);
if (isValidProjectName(project.name)) {
return false;
}
return true;
});
- await batchGetProjects(distinctProjectList, true /* silent */);
- return distinctProjectList.map(getProjectByName);
+ await batchGetProjects(pendingFetch, true /* silent */);
+ return validProjectList.map(getProjectByName);
};
const getOrFetchProjectByName = async (name: string, silent = true) => {