Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Use a separate databaseListByProjectId to avoid interference with databaseListByInstanceId
天舟930283f84ba5
diff --git a/frontend/src/components/AlterSchemaPrepForm.vue b/frontend/src/components/AlterSchemaPrepForm.vueindex 37f253ffa2..eb38c89f2c 100644--- a/frontend/src/components/AlterSchemaPrepForm.vue+++ b/frontend/src/components/AlterSchemaPrepForm.vue@@ -204,7 +204,6 @@ import { useRouter } from "vue-router";import DatabaseTable from "../components/DatabaseTable.vue";import {baseDirectoryWebURL,- Database,DatabaseId,EnvironmentId,Project,@@ -212,6 +211,7 @@ import {Repository,} from "../types";import { sortDatabaseList } from "../utils";+import { cloneDeep } from "lodash";type AlterType = "SINGLE_DB" | "MULTI_DB";@@ -276,7 +276,7 @@ export default {);}- return sortDatabaseList(list, environmentList.value);+ return sortDatabaseList(cloneDeep(list), environmentList.value);});const allowGenerateMultiDb = computed(() => {diff --git a/frontend/src/store/modules/database.ts b/frontend/src/store/modules/database.tsindex a71ddd0ddf..fecb919a0a 100644--- a/frontend/src/store/modules/database.ts+++ b/frontend/src/store/modules/database.ts@@ -114,6 +114,7 @@ const databaseSorter = (a: Database, b: Database): number => {const state: () => DatabaseState = () => ({databaseListByInstanceId: new Map(),+ databaseListByProjectId: new Map(),});const getters = {@@ -163,15 +164,7 @@ const getters = {databaseListByProjectId:(state: DatabaseState) =>(projectId: ProjectId): Database[] => {- const list: Database[] = [];- for (let [_, databaseList] of state.databaseListByInstanceId) {- databaseList.forEach((item: Database) => {- if (item.project.id == projectId) {- list.push(item);- }- });- }- return list;+ return state.databaseListByProjectId.get(projectId) || [];},databaseById:@@ -226,7 +219,7 @@ const actions = {});databaseList.sort(databaseSorter);- commit("upsertDatabaseList", { databaseList });+ commit("setDatabaseListByProjectId", { databaseList, projectId });return databaseList;},@@ -340,6 +333,19 @@ const actions = {};const mutations = {+ setDatabaseListByProjectId(+ state: DatabaseState,+ {+ databaseList,+ projectId,+ }: {+ databaseList: Database[];+ projectId: ProjectId;+ }+ ) {+ state.databaseListByProjectId.set(projectId, databaseList);+ },+upsertDatabaseList(state: DatabaseState,{diff --git a/frontend/src/types/store.ts b/frontend/src/types/store.tsindex 2ff78ca066..cca50156c1 100644--- a/frontend/src/types/store.ts+++ b/frontend/src/types/store.ts@@ -101,11 +101,12 @@ export interface DataSourceState {export interface DatabaseState {// UI may fetch the database list from different dimension (by user, by environment).// In those cases, we will iterate through this map and compute the list on the fly.- // By keeping a single map, we avoid caching inconsistency issue.// We save it by instance because database belongs to instance and saving this way// follows that hierarchy.- // If this causes performance issue, we will add caching later (and deal with the consistency)databaseListByInstanceId: Map<InstanceId, Database[]>;+ // Used exclusively for project panel, we do this to avoid interference from databaseListByInstanceId+ // where updating databaseListByInstanceId will cause reloading project related UI due to reactivity+ databaseListByProjectId: Map<ProjectId, Database[]>;}export interface TableState {diff --git a/frontend/src/views/DatabaseDashboard.vue b/frontend/src/views/DatabaseDashboard.vueindex fe66971625..75cde7233a 100644--- a/frontend/src/views/DatabaseDashboard.vue+++ b/frontend/src/views/DatabaseDashboard.vue@@ -39,6 +39,7 @@ import EnvironmentTabFilter from "../components/EnvironmentTabFilter.vue";import DatabaseTable from "../components/DatabaseTable.vue";import { Environment, Database, UNKNOWN_ID } from "../types";import { sortDatabaseList } from "../utils";+import { cloneDeep } from "lodash";interface LocalState {searchText: string;@@ -95,7 +96,10 @@ export default {// It will also be called when user logoutif (currentUser.value.id != UNKNOWN_ID) {store.dispatch("database/fetchDatabaseList").then((list) => {- state.databaseList = sortDatabaseList(list, environmentList.value);+ state.databaseList = sortDatabaseList(+ cloneDeep(list),+ environmentList.value+ );});}};