Skip to content

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

refactor(frontend): make use of multiple typePrefixes to reduce request count (#3892)

ZhengXf822a8a9f92a
diff --git a/frontend/src/components/ProjectActivityPanel.vue b/frontend/src/components/ProjectActivityPanel.vue
index 5222e2e4e4..8a9c054d17 100644
--- a/frontend/src/components/ProjectActivityPanel.vue
+++ b/frontend/src/components/ProjectActivityPanel.vue
@@ -35,20 +35,13 @@ export default defineComponent({
const activityStore = useActivityStore();
const prepareActivityList = () => {
- const requests = [
- activityStore.fetchActivityListForDatabaseByProjectId({
+ activityStore
+ .fetchActivityListForProject({
projectId: props.project.id,
- }),
- activityStore.fetchActivityListForProject({
- projectId: props.project.id,
- }),
- ];
-
- Promise.all(requests).then((lists) => {
- const flattenList = lists.flatMap((list) => list);
- flattenList.sort((a, b) => -(a.createdTs - b.createdTs)); // by createdTs DESC
- state.activityList = flattenList;
- });
+ })
+ .then((list) => {
+ state.activityList = list;
+ });
};
onBeforeMount(prepareActivityList);
diff --git a/frontend/src/components/ProjectOverviewPanel.vue b/frontend/src/components/ProjectOverviewPanel.vue
index 1eb5ac4683..a25a3eeb0d 100644
--- a/frontend/src/components/ProjectOverviewPanel.vue
+++ b/frontend/src/components/ProjectOverviewPanel.vue
@@ -145,24 +145,15 @@ export default defineComponent({
const prepareActivityList = () => {
state.isFetchingActivityList = true;
state.activityList = [];
- const requests = [
- activityStore.fetchActivityListForDatabaseByProjectId({
+ activityStore
+ .fetchActivityListForProject({
projectId: props.project.id,
limit: ACTIVITY_LIMIT,
- }),
- activityStore.fetchActivityListForProject({
- projectId: props.project.id,
- limit: ACTIVITY_LIMIT,
- }),
- ];
-
- Promise.all(requests).then((lists) => {
- const flattenList = lists.flatMap((list) => list);
- flattenList.sort((a, b) => -(a.createdTs - b.createdTs)); // by createdTs DESC
- state.activityList = flattenList.slice(0, ACTIVITY_LIMIT);
-
- state.isFetchingActivityList = false;
- });
+ })
+ .then((list) => {
+ state.activityList = list.slice(0, ACTIVITY_LIMIT);
+ state.isFetchingActivityList = false;
+ });
};
const isTenantProject = computed((): boolean => {
diff --git a/frontend/src/store/modules/activity.ts b/frontend/src/store/modules/activity.ts
index 532bbd13cf..083a1d0eb2 100644
--- a/frontend/src/store/modules/activity.ts
+++ b/frontend/src/store/modules/activity.ts
@@ -88,12 +88,14 @@ export const useActivityStore = defineStore("activity", {
return activityList;
},
async fetchActivityList(params: {
- typePrefix: string;
+ typePrefix: string | string[];
container: number | string;
order: "ASC" | "DESC";
limit?: number;
}) {
- const url = `/api/activity?${stringify(params)}`;
+ const url = `/api/activity?${stringify(params, {
+ arrayFormat: "repeat",
+ })}`;
const response = (await axios.get(url)).data;
const activityList: Activity[] = response.data.map(
(activity: ResourceObject) => {
@@ -103,35 +105,17 @@ export const useActivityStore = defineStore("activity", {
return activityList;
},
async fetchActivityListForIssue(issue: Issue) {
- const requestListForIssue = this.fetchActivityList({
- typePrefix: "bb.issue.",
+ const activityList = await this.fetchActivityList({
+ typePrefix: ["bb.issue.", "bb.pipeline."],
container: issue.id,
order: "ASC",
});
- const requestListForPipeline = this.fetchActivityList({
- typePrefix: "bb.pipeline.",
- container: issue.pipeline.id,
- order: "ASC",
- });
- const [listForIssue, listForPipeline] = await Promise.all([
- requestListForIssue,
- requestListForPipeline,
- ]);
-
- const mergedList = [...listForIssue, ...listForPipeline];
- mergedList.sort((a, b) => {
- if (a.createdTs !== b.createdTs) {
- return a.createdTs - b.createdTs;
- }
-
- return a.id - b.id;
- });
this.setActivityListForIssue({
issueId: issue.id,
- activityList: mergedList,
+ activityList,
});
- return mergedList;
+ return activityList;
},
async fetchActivityListByIssueId(issueId: IssueId) {
const issue = useIssueStore().getIssueById(issueId);
@@ -148,21 +132,12 @@ export const useActivityStore = defineStore("activity", {
projectId: ProjectId;
limit?: number;
}) {
- const queryList = [
- "typePrefix=bb.project.",
- `container=${projectId}`,
- `order=DESC`,
- ];
- if (limit) {
- queryList.push(`limit=${limit}`);
- }
- const data = (await axios.get(`/api/activity?${queryList.join("&")}`))
- .data;
- const activityList: Activity[] = data.data.map(
- (activity: ResourceObject) => {
- return convert(activity, data.included);
- }
- );
+ const activityList = await this.fetchActivityList({
+ typePrefix: ["bb.project.", "bb.database."],
+ container: projectId,
+ order: "DESC",
+ limit,
+ });
return activityList;
},
@@ -198,31 +173,6 @@ export const useActivityStore = defineStore("activity", {
// return the first `limit` rows
return mixedList.slice(0, limit);
},
- async fetchActivityListForDatabaseByProjectId({
- projectId,
- limit,
- }: {
- projectId: ProjectId;
- limit?: number;
- }) {
- const queryList = [
- "typePrefix=bb.database.",
- `container=${projectId}`,
- `order=DESC`,
- ];
- if (limit) {
- queryList.push(`limit=${limit}`);
- }
- const data = (await axios.get(`/api/activity?${queryList.join("&")}`))
- .data;
- const activityList: Activity[] = data.data.map(
- (activity: ResourceObject) => {
- return convert(activity, data.included);
- }
- );
-
- return activityList;
- },
async createActivity(newActivity: ActivityCreate) {
const data = (
await axios.post(`/api/activity`, {