Skip to content

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

fix: fetch full view for db group in detail page (#12337)

boojackc976d2fe4f7d
diff --git a/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue b/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
index b1a8cb1ad5..63cb2e7dbf 100644
--- a/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
+++ b/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
@@ -77,9 +77,7 @@ import type {
ResourceId,
ValidatedMessage,
} from "@/types";
-import type {
- DatabaseGroup,
-} from "@/types/proto/v1/project_service";
+import type { DatabaseGroup } from "@/types/proto/v1/project_service";
import { getErrorCode } from "@/utils/grpcweb";
import { ProjectSelect, ResourceIdField } from "../v2";
import MatchedDatabaseView from "./MatchedDatabaseView.vue";
@@ -126,7 +124,8 @@ onMounted(async () => {
state.resourceId = databaseGroupName;
state.placeholder = databaseGroupEntity.databasePlaceholder;
const composedDatabaseGroup = await dbGroupStore.getOrFetchDBGroupByName(
- databaseGroup.name
+ databaseGroup.name,
+ { silent: true }
);
if (composedDatabaseGroup.simpleExpr) {
state.expr = cloneDeep(composedDatabaseGroup.simpleExpr);
@@ -142,7 +141,7 @@ const validateResourceId = async (
const request = dbGroupStore.getOrFetchDBGroupByName(
`${props.project.name}/${databaseGroupNamePrefix}${resourceId}`,
- true /* silent */
+ { silent: true }
);
if (!request) {
diff --git a/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue b/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue
index ec7a9683e9..ad35b6b6a9 100644
--- a/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue
+++ b/frontend/src/components/Plan/components/SpecListSection/SpecCard.vue
@@ -76,6 +76,7 @@ import {
PlanCheckRun_Result_Status,
type Plan_Spec,
} from "@/types/proto/v1/plan_service";
+import { DatabaseGroupView } from "@/types/proto/v1/project_service";
import {
databaseForSpec,
isDatabaseChangeSpec,
@@ -140,7 +141,11 @@ const planCheckStatus = computed((): PlanCheckRun_Result_Status => {
onMounted(async () => {
if (isGroupingChangeSpec(props.spec)) {
await dbGroupStore.getOrFetchDBGroupByName(
- props.spec.changeDatabaseConfig!.target
+ props.spec.changeDatabaseConfig!.target,
+ {
+ skipCache: true,
+ view: DatabaseGroupView.DATABASE_GROUP_VIEW_FULL,
+ }
);
}
});
diff --git a/frontend/src/store/modules/dbGroup.ts b/frontend/src/store/modules/dbGroup.ts
index dde80c7e46..c61eed5d15 100644
--- a/frontend/src/store/modules/dbGroup.ts
+++ b/frontend/src/store/modules/dbGroup.ts
@@ -80,6 +80,7 @@ const batchComposeDatabaseGroup = async (
};
export const useDBGroupStore = defineStore("db-group", () => {
+ // TODO(steven): update cache key with view.
const dbGroupMapByName = ref<Map<string, ComposedDatabaseGroup>>(new Map());
const cachedProjectNameSet = ref<Set<string>>(new Set());
@@ -101,13 +102,31 @@ export const useDBGroupStore = defineStore("db-group", () => {
return Array.from(dbGroupMapByName.value.values());
};
- const getOrFetchDBGroupByName = async (name: string, silent = false) => {
- const cached = dbGroupMapByName.value.get(name);
- if (cached) return cached;
+ const getOrFetchDBGroupByName = async (
+ name: string,
+ options?: Partial<{
+ skipCache: boolean;
+ silent: boolean;
+ view: DatabaseGroupView;
+ }>
+ ) => {
+ const { skipCache, silent, view } = {
+ ...{
+ skipCache: false,
+ silent: false,
+ view: DatabaseGroupView.DATABASE_GROUP_VIEW_BASIC,
+ },
+ ...options,
+ };
+ if (!skipCache) {
+ const cached = dbGroupMapByName.value.get(name);
+ if (cached) return cached;
+ }
const databaseGroup = await projectServiceClient.getDatabaseGroup(
{
- name: name,
+ name,
+ view,
},
{ silent }
);
diff --git a/frontend/src/views/DatabaseGroupDetail.vue b/frontend/src/views/DatabaseGroupDetail.vue
index 7b6143c7d6..74ef30246c 100644
--- a/frontend/src/views/DatabaseGroupDetail.vue
+++ b/frontend/src/views/DatabaseGroupDetail.vue
@@ -120,13 +120,17 @@ import type { ConditionGroupExpr } from "@/plugins/cel";
import {
useCurrentUserV1,
useDBGroupStore,
+ useDatabaseV1Store,
useProjectV1Store,
useSubscriptionV1Store,
} from "@/store";
import { databaseGroupNamePrefix } from "@/store/modules/v1/common";
import { projectNamePrefix } from "@/store/modules/v1/common";
import type { ComposedDatabase, ComposedDatabaseGroup } from "@/types";
-import type { DatabaseGroup } from "@/types/proto/v1/project_service";
+import {
+ DatabaseGroupView,
+ type DatabaseGroup,
+} from "@/types/proto/v1/project_service";
import { hasPermissionToCreateChangeDatabaseIssueInProject } from "@/utils";
import { generateDatabaseGroupIssueRoute } from "@/utils/databaseGroup/issue";
@@ -150,6 +154,7 @@ const props = defineProps<{
const router = useRouter();
const projectStore = useProjectV1Store();
const dbGroupStore = useDBGroupStore();
+const databaseStore = useDatabaseV1Store();
const subscriptionV1Store = useSubscriptionV1Store();
const me = useCurrentUserV1();
@@ -180,7 +185,10 @@ const hasPermissionToCreateIssue = computed(() => {
});
onMounted(async () => {
- await dbGroupStore.getOrFetchDBGroupByName(databaseGroupResourceName.value);
+ await dbGroupStore.getOrFetchDBGroupByName(databaseGroupResourceName.value, {
+ skipCache: true,
+ view: DatabaseGroupView.DATABASE_GROUP_VIEW_FULL,
+ });
});
const handleEditDatabaseGroup = () => {
@@ -216,24 +224,23 @@ const updateDatabaseMatchingState = useDebounceFn(async () => {
if (!state.isLoaded) {
return;
}
- if (!project.value) {
- return;
- }
- if (!state.expr) {
- return;
- }
-
- const result = await dbGroupStore.fetchDatabaseGroupMatchList({
- projectName: project.value.name,
- expr: state.expr,
- });
- matchedDatabaseList.value = result.matchedDatabaseList;
- unmatchedDatabaseList.value = result.unmatchedDatabaseList;
+ const matched = await Promise.all(
+ databaseGroup.value.matchedDatabases.map((db) =>
+ databaseStore.getOrFetchDatabaseByName(db.name)
+ )
+ );
+ const unmatched = await Promise.all(
+ databaseGroup.value.unmatchedDatabases.map((db) =>
+ databaseStore.getOrFetchDatabaseByName(db.name)
+ )
+ );
+ matchedDatabaseList.value = matched;
+ unmatchedDatabaseList.value = unmatched;
}, 500);
watch(
- [() => state.isLoaded, () => project.value, () => state.expr],
+ [() => state.isLoaded, () => project.value, () => databaseGroup.value],
updateDatabaseMatchingState,
{
immediate: true,