Skip to content

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

feat: speed-up issue detail page (#3964)

Liu Jifab5e424ff9d
diff --git a/frontend/src/plugins/issue/logic/initialize/index.ts b/frontend/src/plugins/issue/logic/initialize/index.ts
index bd0d7789c9..4e6ef7ee36 100644
--- a/frontend/src/plugins/issue/logic/initialize/index.ts
+++ b/frontend/src/plugins/issue/logic/initialize/index.ts
@@ -1,8 +1,8 @@
import { computed, ref, Ref, watch } from "vue";
-import { useRoute } from "vue-router";
-import type { IssueCreate, IssueType } from "@/types";
+import { type LocationQuery, useRoute, useRouter } from "vue-router";
+import type { Issue, IssueCreate, IssueType } from "@/types";
import { SYSTEM_BOT_ID, UNKNOWN_ID } from "@/types";
-import { pushNotification, useIssueStore } from "@/store";
+import { pushNotification, useDatabaseStore, useIssueStore } from "@/store";
import { idFromSlug } from "@/utils";
import { defaultTemplate, templateForType } from "@/plugins";
import { BuildNewIssueContext } from "../common";
@@ -15,13 +15,9 @@ export function useInitializeIssue(issueSlug: Ref<string>) {
const issueStore = useIssueStore();
const create = computed(() => issueSlug.value.toLowerCase() == "new");
const route = useRoute();
- const issueCreate = ref<IssueCreate | undefined>();
+ const router = useRouter();
- const issue = computed(() => {
- return create.value
- ? issueCreate.value
- : issueStore.getIssueById(idFromSlug(issueSlug.value));
- });
+ const issue = ref<Issue | IssueCreate | undefined>();
const template = computed(() => {
// Find proper IssueTemplate from route.query.template
@@ -43,20 +39,31 @@ export function useInitializeIssue(issueSlug: Ref<string>) {
return defaultTemplate();
});
- // initialize or re-initialize issue when issueSlug changes
watch(
- issueSlug,
- async () => {
- issueCreate.value = undefined;
- if (create.value) {
- issueCreate.value = await buildNewIssue({ template, route });
- if (
- issueCreate.value.assigneeId === UNKNOWN_ID ||
- issueCreate.value.assigneeId === SYSTEM_BOT_ID
- ) {
- // Try to find a default assignee of the first task automatically.
- await tryGetDefaultAssignee(issueCreate.value);
+ [issueSlug, create],
+ async ([issueSlug, create]) => {
+ issue.value = undefined;
+
+ try {
+ if (create) {
+ await prepareDatabaseListForIssueCreation(route.query);
+
+ issue.value = await buildNewIssue({ template, route });
+ if (
+ issue.value.assigneeId === UNKNOWN_ID ||
+ issue.value.assigneeId === SYSTEM_BOT_ID
+ ) {
+ // Try to find a default assignee of the first task automatically.
+ await tryGetDefaultAssignee(issue.value);
+ }
+ } else {
+ const id = idFromSlug(issueSlug);
+ const fetchedIssue = await issueStore.fetchIssueById(id);
+ issue.value = fetchedIssue;
}
+ } catch (error) {
+ router.push({ name: "error.404" });
+ throw error;
}
},
{ immediate: true }
@@ -80,3 +87,33 @@ const buildNewIssue = async (
return buildNewStandardIssue(context);
};
+
+const prepareDatabaseListForIssueCreation = async (query: LocationQuery) => {
+ const databaseStore = useDatabaseStore();
+ // For preparing the database if user visits creating issue url directly.
+ // 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.
+ if (query.project) {
+ // If we found query.project, we can directly fetchDatabaseListByProjectId
+ const projectId = 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 = (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);
+ }
+ }
+ }
+};
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 75baca7ecb..0c9cb35c7e 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -40,7 +40,6 @@ import {
useDatabaseStore,
useEnvironmentStore,
useInstanceStore,
- useIssueStore,
usePrincipalStore,
useRouterStore,
useDBSchemaStore,
@@ -842,14 +841,6 @@ const routes: Array<RouteRecordRaw> = [
path: "issue/:issueSlug",
name: "workspace.issue.detail",
meta: {
- title: (route: RouteLocationNormalized) => {
- const slug = route.params.issueSlug as string;
- if (slug.toLowerCase() == "new") {
- return t("issue.new-issue");
- }
- const issue = useIssueStore().getIssueById(idFromSlug(slug));
- return issue.name;
- },
allowBookmark: true,
},
components: {
@@ -952,7 +943,6 @@ router.beforeEach((to, from, next) => {
const dbSchemaStore = useDBSchemaStore();
const environmentStore = useEnvironmentStore();
const instanceStore = useInstanceStore();
- const issueStore = useIssueStore();
const routerStore = useRouterStore();
const projectWebhookStore = useProjectWebhookStore();
const projectStore = useProjectStore();
@@ -1234,62 +1224,9 @@ router.beforeEach((to, from, next) => {
}
if (issueSlug) {
- if (issueSlug.toLowerCase() == "new") {
- // For preparing the database if user visits creating issue url directly.
- // 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
- );
- }
- }
- }
- };
- prepare()
- .then(() => next())
- .catch((error) => {
- next({
- name: "error.404",
- replace: false,
- });
- throw error;
- });
- return;
- }
- issueStore
- .fetchIssueById(idFromSlug(issueSlug))
- .then(() => {
- next();
- })
- .catch((error) => {
- next({
- name: "error.404",
- replace: false,
- });
- throw error;
- });
+ // We've moved the preparation data fetch jobs into IssueDetail page
+ // so just next() here.
+ next();
return;
}
diff --git a/frontend/src/views/IssueDetail.vue b/frontend/src/views/IssueDetail.vue
index 9e549a800e..26ac4fdc87 100644
--- a/frontend/src/views/IssueDetail.vue
+++ b/frontend/src/views/IssueDetail.vue
@@ -32,9 +32,12 @@ import {
Project,
unknown,
UNKNOWN_ID,
+ Issue,
} from "@/types";
import { hasFeature, useIssueStore, useProjectStore } from "@/store";
import { useInitializeIssue, usePollIssue } from "@/plugins/issue/logic";
+import { useTitle } from "@vueuse/core";
+import { useI18n } from "vue-i18n";
interface LocalState {
showFeatureModal: boolean;
@@ -48,6 +51,7 @@ const props = defineProps({
});
const route = useRoute();
+const { t } = useI18n();
const state = reactive<LocalState>({
showFeatureModal: false,
@@ -100,4 +104,18 @@ const findProject = async (): Promise<Project> => {
return project;
};
+
+const documentTitle = computed(() => {
+ if (create.value) {
+ return t("issue.new-issue");
+ } else {
+ const issueEntity = issue.value as Issue | undefined;
+
+ if (issueEntity) {
+ return issueEntity.name;
+ }
+ return t("common.loading");
+ }
+});
+useTitle(documentTitle);
</script>