Skip to content

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

fix(frontend): improve issue preview load latency (#3805)

Liu Ji7b6dfbe99024
diff --git a/frontend/src/components/Issue/PipelineGhostFlow.vue b/frontend/src/components/Issue/PipelineGhostFlow.vue
index eb068531cf..bb5549557b 100644
--- a/frontend/src/components/Issue/PipelineGhostFlow.vue
+++ b/frontend/src/components/Issue/PipelineGhostFlow.vue
@@ -64,7 +64,7 @@
</template>
<script lang="ts" setup>
-import { computed, watchEffect } from "vue";
+import { computed } from "vue";
import { useI18n } from "vue-i18n";
import type {
Pipeline,
@@ -85,23 +85,11 @@ import { useIssueLogic } from "./logic";
const { t } = useI18n();
const databaseStore = useDatabaseStore();
-const {
- create,
- issue,
- project,
- selectedStage,
- selectedTask,
- selectStageOrTask,
-} = useIssueLogic();
+const { create, issue, selectedStage, selectedTask, selectStageOrTask } =
+ useIssueLogic();
const pipeline = computed(() => issue.value.pipeline!);
-watchEffect(() => {
- if (create.value) {
- databaseStore.fetchDatabaseListByProjectId(project.value.id);
- }
-});
-
const taskList = computed(() => {
return selectedStage.value.taskList;
});
diff --git a/frontend/src/components/Issue/PipelinePITRFlow.vue b/frontend/src/components/Issue/PipelinePITRFlow.vue
index 973e38e5bc..fa673044b2 100644
--- a/frontend/src/components/Issue/PipelinePITRFlow.vue
+++ b/frontend/src/components/Issue/PipelinePITRFlow.vue
@@ -64,7 +64,7 @@
</template>
<script lang="ts" setup>
-import { computed, watchEffect } from "vue";
+import { computed } from "vue";
import { Pipeline, Stage, StageCreate, Task, TaskCreate } from "@/types";
import {
activeTask,
@@ -74,30 +74,15 @@ import {
bytesToString,
} from "@/utils";
import TaskStatusIcon from "./TaskStatusIcon.vue";
-import { useDatabaseStore } from "@/store";
import PipelineStageList from "./PipelineStageList.vue";
import TaskMarkAsDoneButton from "./TaskMarkAsDoneButton.vue";
import { useIssueLogic } from "./logic";
-const databaseStore = useDatabaseStore();
-
-const {
- create,
- issue,
- project,
- selectedStage,
- selectedTask,
- selectStageOrTask,
-} = useIssueLogic();
+const { create, issue, selectedStage, selectedTask, selectStageOrTask } =
+ useIssueLogic();
const pipeline = computed(() => issue.value.pipeline!);
-watchEffect(() => {
- if (create.value) {
- databaseStore.fetchDatabaseListByProjectId(project.value.id);
- }
-});
-
const taskList = computed(() => {
return selectedStage.value.taskList;
});
diff --git a/frontend/src/components/Issue/PipelineSimpleFlow.vue b/frontend/src/components/Issue/PipelineSimpleFlow.vue
index 64ea25aa53..5d601acce7 100644
--- a/frontend/src/components/Issue/PipelineSimpleFlow.vue
+++ b/frontend/src/components/Issue/PipelineSimpleFlow.vue
@@ -66,7 +66,7 @@
</template>
<script lang="ts" setup>
-import { computed, ref, watchEffect } from "vue";
+import { computed, ref } from "vue";
import { useDatabaseStore } from "@/store";
import {
@@ -207,12 +207,6 @@ const onClickTask = (task: Task | TaskCreate, index: number) => {
selectStageOrTask(stageId, ts);
};
-
-watchEffect(() => {
- if (create.value) {
- databaseStore.fetchDatabaseListByProjectId(project.value.id);
- }
-});
</script>
<style scoped lang="postcss">
diff --git a/frontend/src/components/Issue/PipelineTenantFlow.vue b/frontend/src/components/Issue/PipelineTenantFlow.vue
index 13bb00fb0d..e04dcb10b2 100644
--- a/frontend/src/components/Issue/PipelineTenantFlow.vue
+++ b/frontend/src/components/Issue/PipelineTenantFlow.vue
@@ -54,7 +54,7 @@
</template>
<script lang="ts" setup>
-import { computed, ref, watchEffect } from "vue";
+import { computed, ref } from "vue";
import type {
Pipeline,
Stage,
@@ -70,14 +70,8 @@ import { useDatabaseStore } from "@/store";
import { useIssueLogic } from "./logic";
import { useScroll } from "@vueuse/core";
-const {
- create,
- issue,
- project,
- selectedStage,
- selectedTask,
- selectStageOrTask,
-} = useIssueLogic();
+const { create, issue, selectedStage, selectedTask, selectStageOrTask } =
+ useIssueLogic();
const pipeline = computed(() => issue.value.pipeline!);
@@ -86,12 +80,6 @@ const taskBar = ref<HTMLDivElement>();
const taskBarScrollState = useScroll(taskBar);
-watchEffect(() => {
- if (create.value) {
- databaseStore.fetchDatabaseListByProjectId(project.value.id);
- }
-});
-
const taskList = computed(() => selectedStage.value.taskList);
const isSelectedTask = (task: Task | TaskCreate): boolean => {
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 0889c5bce4..ab34ca6f27 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -1206,18 +1206,39 @@ router.beforeEach((to, from, next) => {
if (issueSlug) {
if (issueSlug.toLowerCase() == "new") {
// For preparing the database if user visits creating issue url directly.
- const requests: Promise<any>[] = [];
- if (to.query.databaseList) {
- for (const databaseId of (to.query.databaseList as string).split(",")) {
- requests.push(
- databaseStore.fetchDatabaseById(parseInt(databaseId, 10))
+ // It's horrible to fetchDatabaseById one-by-one when query.databaseList
+ // is big (100+ sometimes)
+ // So we are fetching databaseList by project since that's better cached.
+ const prepare = async () => {
+ if (to.query.project) {
+ // If we found query.project, we can directly fetchDatabaseListByProjectId
+ const projectId = to.query.project as string;
+ await databaseStore.fetchDatabaseListByProjectId(
+ parseInt(projectId, 10)
);
+ } else {
+ // Otherwise, we don't have the projectId (very rare to see, theoretically)
+ // so we need to fetch the first database in databaseList by id,
+ // and see what project it belongs.
+ const databaseIdList = (to.query.databaseList as string)
+ .split(",")
+ .map((str) => parseInt(str, 10));
+ if (databaseIdList.length > 0) {
+ const firstDB = await databaseStore.getOrFetchDatabaseById(
+ databaseIdList[0]
+ );
+ if (databaseIdList.length > 1) {
+ // If we have more than one databases in the list
+ // fetch the rest of databases by projectId
+ await databaseStore.fetchDatabaseListByProjectId(
+ firstDB.project.id
+ );
+ }
+ }
}
- }
- Promise.all(requests)
- .then(() => {
- next();
- })
+ };
+ prepare()
+ .then(() => next())
.catch((error) => {
next({
name: "error.404",