Skip to content

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

Fetches all databases upon initializing the context

天舟1e85384c20ca
diff --git a/frontend/src/components/ProvideContext.vue b/frontend/src/components/ProvideContext.vue
index ef38113625..1e3b04525d 100644
--- a/frontend/src/components/ProvideContext.vue
+++ b/frontend/src/components/ProvideContext.vue
@@ -20,6 +20,17 @@ export default {
// fetchPrincipalList relies on fetchRoleMappingList to find the role of the principal.
store.dispatch("principal/fetchPrincipalList"),
store.dispatch("instance/fetchInstanceList"),
+ // [TODO] Fetches all databases. This may cause performance issue if the entire fleet
+ // has a lot of databases.
+ // The purpose it serves is our task list in the home view displays the database name column.
+ // User with the Developer role may subscribe to the task, while she is not granted to that task's
+ // related database. In such case, user won't fetch that task by her user id, so we need to do
+ // a separate fetch somewhere. Another way to do it is to do on-demand fetch for each task whose
+ // database hasn't been fetched yet, that solution is more complex and might not bring better
+ // performance because it requires to do more round-trips because of the N+1 nature. Thus,
+ // we choose to do a full fetch when initializing the context here.
+ // [TODO] The backend needs to redact the password info for database which the user is not granted.
+ store.dispatch("database/fetchDatabaseList"),
store.dispatch("uistate/restoreState"),
]);
diff --git a/frontend/src/miragejs/routes/database.js b/frontend/src/miragejs/routes/database.js
index 05dfebc4f8..6c8d874f88 100644
--- a/frontend/src/miragejs/routes/database.js
+++ b/frontend/src/miragejs/routes/database.js
@@ -22,16 +22,15 @@ export default function configureDatabase(route) {
user: userId,
},
} = request;
- if (!environmentId && !instanceId && !userId) {
- return schema.databases.all();
- }
const instanceIdList = instanceId
? [instanceId]
: environmentId
? schema.instances
.where({ workspaceId: WORKSPACE_ID, environmentId })
.models.map((instance) => instance.id)
- : undefined;
+ : schema.instances
+ .where({ workspaceId: WORKSPACE_ID })
+ .models.map((instance) => instance.id);
if (instanceIdList && instanceIdList.length == 0) {
return [];
}
diff --git a/frontend/src/store/modules/database.ts b/frontend/src/store/modules/database.ts
index d62b398c6a..b14f51b7ef 100644
--- a/frontend/src/store/modules/database.ts
+++ b/frontend/src/store/modules/database.ts
@@ -137,6 +137,18 @@ const getters = {
};
const actions = {
+ async fetchDatabaseList({ commit, rootGetters }: any) {
+ const data = (await axios.get(`/api/database?include=instance,dataSource`))
+ .data;
+ const databaseList = data.data.map((database: ResourceObject) => {
+ return convert(database, data.included, rootGetters);
+ });
+
+ commit("upsertDatabaseList", { databaseList });
+
+ return databaseList;
+ },
+
async fetchDatabaseListByInstanceId(
{ commit, rootGetters }: any,
instanceId: InstanceId