Skip to content

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

chore: optimize batch request (#18503)

ecmadao4b5673a205be
diff --git a/frontend/src/AuthContext.vue b/frontend/src/AuthContext.vue
index 77fabe019f..00316851ce 100644
--- a/frontend/src/AuthContext.vue
+++ b/frontend/src/AuthContext.vue
@@ -16,10 +16,10 @@ import SigninModal from "@/views/auth/SigninModal.vue";
import { t } from "./plugins/i18n";
import { WORKSPACE_ROOT_MODULE } from "./router/dashboard/workspaceRoutes";
import {
+ batchGetOrFetchGroups,
pushNotification,
useAuthStore,
useCurrentUserV1,
- useGroupStore,
useRoleStore,
useWorkspaceV1Store,
} from "./store";
@@ -33,7 +33,6 @@ const router = useRouter();
const authStore = useAuthStore();
const currentUser = useCurrentUserV1();
const workspaceStore = useWorkspaceV1Store();
-const groupStore = useGroupStore();
const roleStore = useRoleStore();
const authCheckIntervalId = ref<NodeJS.Timeout>();
@@ -102,7 +101,7 @@ watch(
workspaceStore.fetchIamPolicy(),
roleStore.fetchRoleList(),
// we only care about the groups for the current user.
- groupStore.batchFetchGroups(currentUser.value.groups),
+ batchGetOrFetchGroups(currentUser.value.groups),
]);
},
{
diff --git a/frontend/src/components/DatabaseGroup/MatchedDatabaseView.vue b/frontend/src/components/DatabaseGroup/MatchedDatabaseView.vue
index e643936173..b7094d90ad 100644
--- a/frontend/src/components/DatabaseGroup/MatchedDatabaseView.vue
+++ b/frontend/src/components/DatabaseGroup/MatchedDatabaseView.vue
@@ -72,7 +72,11 @@ import {
} from "@/components/v2";
import type { ConditionGroupExpr } from "@/plugins/cel";
import { validateSimpleExpr } from "@/plugins/cel";
-import { useDatabaseV1Store, useDBGroupStore } from "@/store";
+import {
+ batchGetOrFetchDatabases,
+ useDatabaseV1Store,
+ useDBGroupStore,
+} from "@/store";
import {
type ComposedDatabase,
DEBOUNCE_SEARCH_DELAY,
@@ -112,12 +116,11 @@ const databaseStore = useDatabaseV1Store();
const loadMoreMatched = async (index: number) => {
const previous = index;
const next = previous + pageSize.value;
- const databases = await databaseStore.batchGetDatabases(
- matchedDatabaseNameList.value.slice(previous, next)
- );
+ const databaseNames = matchedDatabaseNameList.value.slice(previous, next);
+ await batchGetOrFetchDatabases(databaseNames);
return {
- databases,
+ databases: databaseNames.map(databaseStore.getDatabaseByName),
token: next,
};
};
diff --git a/frontend/src/components/GrantRequestPanel/DatabaseResourceForm/DatabaseResourceSelector.vue b/frontend/src/components/GrantRequestPanel/DatabaseResourceForm/DatabaseResourceSelector.vue
index d104f6b631..c00bb105e0 100644
--- a/frontend/src/components/GrantRequestPanel/DatabaseResourceForm/DatabaseResourceSelector.vue
+++ b/frontend/src/components/GrantRequestPanel/DatabaseResourceForm/DatabaseResourceSelector.vue
@@ -303,13 +303,12 @@ onMounted(async () => {
);
const selectedKeys: string[] = [];
+ const databaseNames = new Set<string>();
for (const databaseResource of props.databaseResources) {
selectedKeys.push(...parseResourceToKeys(databaseResource));
+ databaseNames.add(databaseResource.databaseFullName);
}
- const databaseNames = new Set(
- selectedKeys.map((key) => key.split("/schemas/")[0]).filter((key) => key)
- );
await Promise.all(
[...databaseNames].map(async (databaseName) => {
await dbSchemaStore.getOrFetchDatabaseMetadata({
diff --git a/frontend/src/components/Plan/components/IssueReviewView/Sidebar/ApprovalFlowSection/ApprovalStepItem.vue b/frontend/src/components/Plan/components/IssueReviewView/Sidebar/ApprovalFlowSection/ApprovalStepItem.vue
index f92637dbfa..1e26f7cdf3 100644
--- a/frontend/src/components/Plan/components/IssueReviewView/Sidebar/ApprovalFlowSection/ApprovalStepItem.vue
+++ b/frontend/src/components/Plan/components/IssueReviewView/Sidebar/ApprovalFlowSection/ApprovalStepItem.vue
@@ -76,9 +76,9 @@ import { NTimelineItem } from "naive-ui";
import { computed, watchEffect } from "vue";
import { useI18n } from "vue-i18n";
import {
+ batchGetOrFetchGroups,
useCurrentProjectV1,
useCurrentUserV1,
- useGroupStore,
useProjectIamPolicyStore,
useRoleStore,
useUserStore,
@@ -105,7 +105,6 @@ const props = defineProps<{
const { t } = useI18n();
const { project } = useCurrentProjectV1();
-const groupStore = useGroupStore();
const currentUser = useCurrentUserV1();
const userStore = useUserStore();
const roleStore = useRoleStore();
@@ -195,7 +194,7 @@ const stepRoles = computed(() => {
});
watchEffect(async () => {
- const groupNames = new Set<string>();
+ const groupNames: string[] = [];
for (const role of stepRoles.value) {
const policy = projectIamPolicyStore.getProjectIamPolicy(
@@ -206,17 +205,14 @@ watchEffect(async () => {
continue;
}
for (const member of binding.members) {
- if (
- member.startsWith(groupBindingPrefix) &&
- !groupStore.getGroupByIdentifier(member)
- ) {
- groupNames.add(member);
+ if (member.startsWith(groupBindingPrefix)) {
+ groupNames.push(member);
}
}
}
}
- await groupStore.batchFetchGroups([...groupNames]);
+ await batchGetOrFetchGroups(groupNames);
});
// Get candidates for this approval step
diff --git a/frontend/src/components/Plan/components/SpecDetailView/AllTargetsDrawer.vue b/frontend/src/components/Plan/components/SpecDetailView/AllTargetsDrawer.vue
index 29e52e217e..70e6e54e43 100644
--- a/frontend/src/components/Plan/components/SpecDetailView/AllTargetsDrawer.vue
+++ b/frontend/src/components/Plan/components/SpecDetailView/AllTargetsDrawer.vue
@@ -166,24 +166,23 @@ const loadAllTargets = async () => {
}
};
-// Load all targets when drawer opens
watch(
() => props.show,
async (show) => {
if (show) {
state.searchText = "";
- await loadAllTargets();
}
}
);
-// Reload if targets change while drawer is open
+// Load all targets when drawer opens
watch(
- () => props.targets,
- async () => {
- if (props.show) {
+ () => props.show,
+ async (show) => {
+ if (show) {
await loadAllTargets();
}
- }
+ },
+ { once: true }
);
</script>
diff --git a/frontend/src/components/Plan/components/SpecDetailView/TargetListSection.vue b/frontend/src/components/Plan/components/SpecDetailView/TargetListSection.vue
index ee2b6ffae4..a8463a81a4 100644
--- a/frontend/src/components/Plan/components/SpecDetailView/TargetListSection.vue
+++ b/frontend/src/components/Plan/components/SpecDetailView/TargetListSection.vue
@@ -216,7 +216,7 @@ const loadTargetData = async () => {
})
);
- await Promise.allSettled([...dbGroupPromises]);
+ await Promise.allSettled(dbGroupPromises);
} catch {
// Ignore errors
} finally {
diff --git a/frontend/src/components/SchemaEditorLite/Aside/Tree.vue b/frontend/src/components/SchemaEditorLite/Aside/Tree.vue
index 05b1d9218e..acf16e88b1 100644
--- a/frontend/src/components/SchemaEditorLite/Aside/Tree.vue
+++ b/frontend/src/components/SchemaEditorLite/Aside/Tree.vue
@@ -231,7 +231,7 @@ const handleSearch = debounce(
targets.value.map(async (target) => {
const metadata = await dbSchemaStore.getOrFetchDatabaseMetadata({
database: target.database.name,
- skipCache: true,
+ skipCache: false,
limit: 100,
filter: `table.matches("${search.trim()}")`,
});
diff --git a/frontend/src/components/User/Settings/UserDataTable/index.vue b/frontend/src/components/User/Settings/UserDataTable/index.vue
index 143cd9477c..91153c1cb9 100644
--- a/frontend/src/components/User/Settings/UserDataTable/index.vue
+++ b/frontend/src/components/User/Settings/UserDataTable/index.vue
@@ -31,8 +31,8 @@ import { useI18n } from "vue-i18n";
import { BBAlert } from "@/bbkit";
import { UserNameCell } from "@/components/v2/Model/cells";
import {
+ batchGetOrFetchGroups,
pushNotification,
- useGroupStore,
useUserStore,
useWorkspaceV1Store,
} from "@/store";
@@ -68,7 +68,6 @@ const emit = defineEmits<{
const { t } = useI18n();
const userStore = useUserStore();
-const groupStore = useGroupStore();
const workspaceStore = useWorkspaceV1Store();
const { copy: copyTextToClipboard, isSupported } = useClipboard({
@@ -76,15 +75,11 @@ const { copy: copyTextToClipboard, isSupported } = useClipboard({
});
watchEffect(async () => {
- const groupNames = new Set<string>();
+ const groupNames: string[] = [];
for (const user of props.userList) {
- for (const groupName of user.groups) {
- if (!groupStore.getGroupByIdentifier(groupName)) {
- groupNames.add(groupName);
- }
- }
+ groupNames.push(...user.groups);
}
- await groupStore.batchFetchGroups([...groupNames]);
+ await batchGetOrFetchGroups(groupNames);
});
const state = reactive<LocalState>({
diff --git a/frontend/src/store/modules/v1/experimental-issue.ts b/frontend/src/store/modules/v1/experimental-issue.ts
index 4fec342ca3..5d5396fde7 100644
--- a/frontend/src/store/modules/v1/experimental-issue.ts
+++ b/frontend/src/store/modules/v1/experimental-issue.ts
@@ -38,13 +38,12 @@ export interface ComposeIssueConfig {
withRollout?: boolean;
}
-export const composeIssue = async (
+const composeIssue = async (
rawIssue: Issue,
config: ComposeIssueConfig = { withPlan: true, withRollout: true }
): Promise<ComposedIssue> => {
const project = `projects/${extractProjectResourceName(rawIssue.name)}`;
- const projectEntity =
- await useProjectV1Store().getOrFetchProjectByName(project);
+ const projectEntity = useProjectV1Store().getProjectByName(project);
const issue: ComposedIssue = {
...rawIssue,
diff --git a/frontend/src/store/modules/v1/group.ts b/frontend/src/store/modules/v1/group.ts
index 84ff93681b..55cfe49e0d 100644
--- a/frontend/src/store/modules/v1/group.ts
+++ b/frontend/src/store/modules/v1/group.ts
@@ -1,6 +1,6 @@
import { create } from "@bufbuild/protobuf";
import { createContextValues } from "@connectrpc/connect";
-import { orderBy } from "lodash-es";
+import { orderBy, uniq } from "lodash-es";
import { defineStore } from "pinia";
import { computed, reactive } from "vue";
import { groupServiceClientConnect } from "@/grpcweb";
@@ -160,3 +160,21 @@ export const useGroupStore = defineStore("group", () => {
createGroup,
};
});
+
+export const batchGetOrFetchGroups = async (groupNames: string[]) => {
+ const store = useGroupStore();
+
+ const distinctGroupList = uniq(groupNames).filter((groupName) => {
+ if (!groupName) {
+ return false;
+ }
+ const group = store.getGroupByIdentifier(groupName);
+ if (group) {
+ return false;
+ }
+ return true;
+ });
+ if (distinctGroupList.length > 0) {
+ return store.batchFetchGroups(distinctGroupList);
+ }
+};
diff --git a/frontend/src/store/modules/v1/issue.ts b/frontend/src/store/modules/v1/issue.ts
index cc4f617b0a..e88d9008eb 100644
--- a/frontend/src/store/modules/v1/issue.ts
+++ b/frontend/src/store/modules/v1/issue.ts
@@ -28,7 +28,7 @@ import {
type ComposeIssueConfig,
shallowComposeIssue,
} from "./experimental-issue";
-import { useProjectV1Store } from "./project";
+import { batchGetOrFetchProjects, useProjectV1Store } from "./project";
import { useProjectIamPolicyStore } from "./projectIamPolicy";
export type ListIssueParams = {
@@ -84,6 +84,8 @@ export const buildIssueFilter = (find: IssueFilter): string => {
};
export const useIssueV1Store = defineStore("issue_v1", () => {
+ const projectStore = useProjectV1Store();
+
const regenerateReviewV1 = async (name: string) => {
const request = create(UpdateIssueRequestSchema, {
issue: create(IssueSchema, {
@@ -108,6 +110,11 @@ export const useIssueV1Store = defineStore("issue_v1", () => {
});
const resp = await issueServiceClientConnect.searchIssues(request);
const issues = resp.issues;
+
+ const projects = issues.map((issue) => {
+ return `projects/${extractProjectResourceName(issue.name)}`;
+ });
+ await batchGetOrFetchProjects(projects);
const composedIssues = await Promise.all(
issues.map((issue) => shallowComposeIssue(issue, composeIssueConfig))
);
@@ -126,10 +133,12 @@ export const useIssueV1Store = defineStore("issue_v1", () => {
silent: boolean = false
) => {
const request = create(GetIssueRequestSchema, { name });
- const newIssue = await issueServiceClientConnect.getIssue(request, {
+ const issue = await issueServiceClientConnect.getIssue(request, {
contextValues: createContextValues().set(silentContextKey, silent),
});
- const issue = newIssue;
+ await projectStore.getOrFetchProjectByName(
+ `projects/${extractProjectResourceName(issue.name)}`
+ );
return shallowComposeIssue(issue, composeIssueConfig);
};
diff --git a/frontend/src/store/modules/v1/worksheet.ts b/frontend/src/store/modules/v1/worksheet.ts
index da89f5d121..946aeb4f1d 100644
--- a/frontend/src/store/modules/v1/worksheet.ts
+++ b/frontend/src/store/modules/v1/worksheet.ts
@@ -66,14 +66,16 @@ export const useWorkSheetStore = defineStore("worksheet_v1", () => {
});
// Utilities
- const setCache = async (worksheet: Worksheet, view: WorksheetView) => {
+ const setCacheEntry = (worksheet: Worksheet, view: WorksheetView) => {
const uid = extractWorksheetUID(worksheet.name);
if (uid === String(UNKNOWN_ID)) return;
if (view === "FULL") {
- // A FULL version should override BASIC version
cacheByUID.invalidateEntity([uid, "BASIC"]);
}
+ cacheByUID.setEntity([uid, view], worksheet);
+ };
+ const setCache = async (worksheet: Worksheet, view: WorksheetView) => {
try {
await Promise.all([
projectStore.getOrFetchProjectByName(worksheet.project),
@@ -83,8 +85,9 @@ export const useWorkSheetStore = defineStore("worksheet_v1", () => {
} catch {
// ignore error
}
- cacheByUID.setEntity([uid, view], worksheet);
+ setCacheEntry(worksheet, view);
};
+
const setListCache = async (worksheets: Worksheet[]) => {
await Promise.all([
batchGetOrFetchProjects(worksheets.map((worksheet) => worksheet.project)),
@@ -94,7 +97,7 @@ export const useWorkSheetStore = defineStore("worksheet_v1", () => {
userStore.batchGetUsers(worksheets.map((worksheet) => worksheet.creator)),
]);
for (const worksheet of worksheets) {
- await setCache(worksheet, "BASIC");
+ setCacheEntry(worksheet, "BASIC");
}
};
@@ -108,7 +111,7 @@ export const useWorkSheetStore = defineStore("worksheet_v1", () => {
});
const response =
await worksheetServiceClientConnect.createWorksheet(request);
- await setCache(response, "FULL");
+ setCacheEntry(response, "FULL");
return response;
};
@@ -206,7 +209,7 @@ export const useWorkSheetStore = defineStore("worksheet_v1", () => {
});
const response =
await worksheetServiceClientConnect.updateWorksheet(request);
- await setCache(response, "FULL");
+ setCacheEntry(response, "FULL");
return response;
};
@@ -218,21 +221,16 @@ export const useWorkSheetStore = defineStore("worksheet_v1", () => {
cacheByUID.invalidateEntity([uid, "BASIC"]);
};
- const updateWorksheetCacheWithOrganizer = async (
- organizer: WorksheetOrganizer
- ) => {
+ const updateWorksheetCacheWithOrganizer = (organizer: WorksheetOrganizer) => {
// Update local sheet values
- const fullViewWorksheet = getWorksheetByName(organizer.worksheet, "FULL");
- if (fullViewWorksheet) {
- fullViewWorksheet.starred = organizer.starred;
- fullViewWorksheet.folders = organizer.folders;
- await setCache(fullViewWorksheet, "FULL");
- }
- const basicViewWorksheet = getWorksheetByName(organizer.worksheet, "BASIC");
- if (basicViewWorksheet) {
- basicViewWorksheet.starred = organizer.starred;
- basicViewWorksheet.folders = organizer.folders;
- await setCache(basicViewWorksheet, "BASIC");
+ const views: WorksheetView[] = ["FULL", "BASIC"];
+ for (const view of views) {
+ const worksheet = getWorksheetByName(organizer.worksheet, view);
+ if (worksheet) {
+ worksheet.starred = organizer.starred;
+ worksheet.folders = organizer.folders;
+ setCacheEntry(worksheet, view);
+ }
}
};
@@ -257,9 +255,7 @@ export const useWorkSheetStore = defineStore("worksheet_v1", () => {
request
);
- await Promise.all(
- response.worksheetOrganizers.map(updateWorksheetCacheWithOrganizer)
- );
+ response.worksheetOrganizers.map(updateWorksheetCacheWithOrganizer);
};
const upsertWorksheetOrganizer = async (
@@ -274,7 +270,7 @@ export const useWorkSheetStore = defineStore("worksheet_v1", () => {
});
const response =
await worksheetServiceClientConnect.updateWorksheetOrganizer(request);
- await updateWorksheetCacheWithOrganizer(response);
+ updateWorksheetCacheWithOrganizer(response);
};
return {