Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor(frontend): extract rollback and improve StageTimeline performance (#18202)
boojack6fb54cc00f01
diff --git a/frontend/src/components/Plan/components/RolloutView/v2/StageContentView.vue b/frontend/src/components/Plan/components/RolloutView/v2/StageContentView.vueindex 34130b87ed..32746cf01a 100644--- a/frontend/src/components/Plan/components/RolloutView/v2/StageContentView.vue+++ b/frontend/src/components/Plan/components/RolloutView/v2/StageContentView.vue@@ -61,8 +61,6 @@<StageTimeline:stage="selectedStage":task-runs="taskRuns"- :rollout="rollout"- :rollbackable-task-runs="rollbackableTaskRuns":is-inline="true"class="border-y"/>@@ -87,8 +85,6 @@<StageTimeline:stage="selectedStage":task-runs="taskRuns"- :rollout="rollout"- :rollbackable-task-runs="rollbackableTaskRuns":is-inline="false"/></div>@@ -107,13 +103,12 @@import { useMediaQuery } from "@vueuse/core";import { PlayIcon, PlusIcon } from "lucide-vue-next";import { NButton, NTag } from "naive-ui";-import { computed, ref, toRef } from "vue";+import { computed, ref } from "vue";import { EnvironmentV1Name } from "@/components/v2";import { useEnvironmentV1Store } from "@/store";import type { Rollout, Stage } from "@/types/proto-es/v1/rollout_service_pb";import { Task_Status } from "@/types/proto-es/v1/rollout_service_pb";import { usePlanContextWithRollout } from "../../../logic";-import { useRollbackableTasks } from "./composables/useRollbackableTasks";import StageTimeline from "./StageTimeline.vue";import TaskFilter from "./TaskFilter.vue";import TaskList from "./TaskList.vue";@@ -135,13 +130,7 @@ const filterStatuses = ref<Task_Status[]>([]);// Responsive layout: sidebar on wide screen, inline on narrowconst isWideScreen = useMediaQuery("(min-width: 1024px)");-// Rollback functionalityconst { taskRuns } = usePlanContextWithRollout();-const selectedStageRef = toRef(props, "selectedStage");-const { rollbackableTaskRuns } = useRollbackableTasks(- selectedStageRef,- taskRuns-);const canRunStage = computed(() => {if (!props.selectedStage || !props.isStageCreated(props.selectedStage)) {diff --git a/frontend/src/components/Plan/components/RolloutView/v2/StageTaskRunsRollback.vue b/frontend/src/components/Plan/components/RolloutView/v2/StageTaskRunsRollback.vuenew file mode 100644index 0000000000..a334d6f8f4--- /dev/null+++ b/frontend/src/components/Plan/components/RolloutView/v2/StageTaskRunsRollback.vue@@ -0,0 +1,37 @@+<template>+ <div v-if="rollbackableTaskRuns.length > 0" class="px-3 pb-3">+ <NButton size="small" text @click="showRollbackDrawer = true">+ <template #icon>+ <DatabaseBackupIcon :size="16" />+ </template>+ {{ $t("task-run.rollback.available", rollbackableTaskRuns.length) }}+ </NButton>++ <TaskRunRollbackDrawer+ v-model:show="showRollbackDrawer"+ :rollout="rollout"+ :rollbackable-task-runs="rollbackableTaskRuns"+ @close="showRollbackDrawer = false"+ />+ </div>+</template>++<script lang="ts" setup>+import { DatabaseBackupIcon } from "lucide-vue-next";+import { NButton } from "naive-ui";+import { ref, toRef } from "vue";+import type { Stage } from "@/types/proto-es/v1/rollout_service_pb";+import { usePlanContextWithRollout } from "../../../logic";+import TaskRunRollbackDrawer from "../TaskRunRollbackDrawer.vue";+import { useRollbackableTasks } from "./composables/useRollbackableTasks";++const props = defineProps<{+ stage: Stage | null | undefined;+}>();++const { rollout, taskRuns } = usePlanContextWithRollout();+const stageRef = toRef(props, "stage");+const { rollbackableTaskRuns } = useRollbackableTasks(stageRef, taskRuns);++const showRollbackDrawer = ref(false);+</script>diff --git a/frontend/src/components/Plan/components/RolloutView/v2/StageTimeline.vue b/frontend/src/components/Plan/components/RolloutView/v2/StageTimeline.vueindex ddc4cd3894..139d38f609 100644--- a/frontend/src/components/Plan/components/RolloutView/v2/StageTimeline.vue+++ b/frontend/src/components/Plan/components/RolloutView/v2/StageTimeline.vue@@ -15,28 +15,11 @@<span class="text-sm font-medium text-gray-700">{{ $t("task.run-history") }}</span>- <span v-if="stageTaskRuns.length > 0" class="text-gray-500">- ({{ stageTaskRuns.length }})- </span></div></div><!-- Rollback entry -->- <div- v-if="rollbackableTaskRuns.length > 0"- class="px-3 pb-3"- >- <NButton- size="small"- text- @click="showRollbackDrawer = true"- >- <template #icon>- <DatabaseBackupIcon :size="16" />- </template>- {{ $t("task-run.rollback.available", rollbackableTaskRuns.length) }}- </NButton>- </div>+ <StageTaskRunsRollback :stage="stage" /><!-- Timeline entries: always show in sidebar mode, toggle in inline mode --><div@@ -58,7 +41,7 @@</div><NTimeline v-else size="medium"><NTimelineItem- v-for="taskRun in sortedTaskRuns"+ v-for="taskRun in displayedTaskRuns":key="taskRun.name":type="getTimelineType(taskRun.status)">@@ -71,11 +54,10 @@</template><divclass="-ml-1 px-1 py-0.5 rounded -mt-0.5"- @click="handleClickTaskRun(taskRun)"><divclass="text-sm leading-4 truncate cursor-pointer hover:underline"- @click.stop="handleClickTarget(taskRun)"+ @click="handleClickTarget(taskRun)"><spanv-if="getTaskTargetDisplay(taskRun).instance"@@ -95,9 +77,10 @@<!-- Error preview for failed --><divv-if="taskRun.status === TaskRun_Status.FAILED && taskRun.detail"- class="text-xs text-red-600 truncate mt-0.5"+ class="text-xs text-red-600 line-clamp-3 mt-0.5 cursor-pointer hover:underline"+ @click="showDetail(taskRun)">- {{ getErrorPreview(taskRun.detail) }}+ {{ taskRun.detail }}</div><!-- Scheduled run time for pending --><div@@ -106,7 +89,7 @@"class="text-xs text-gray-500 mt-0.5 flex items-center gap-1">-{{ $t("task.scheduled-at") }}+ {{ $t("task.scheduled-at") }}<TimestampDisplay:timestamp="taskRun.runTime"custom-class="!text-xs !text-gray-500"@@ -129,56 +112,62 @@</div></NTimelineItem></NTimeline>+ <!-- Show message if there are more items -->+ <div+ v-if="sortedTaskRuns.length > MAX_DISPLAY_ITEMS"+ class="text-xs text-gray-400 text-left"+ >+ {{ $t("task.only-showing-latest-n-runs", { n: MAX_DISPLAY_ITEMS }) }}+ </div></div>- <!-- Rollback drawer -->- <TaskRunRollbackDrawer- v-model:show="showRollbackDrawer"- :rollout="rollout"- :rollbackable-task-runs="rollbackableTaskRuns"- @close="showRollbackDrawer = false"- /></div>++ <Drawer v-model:show="taskRunDetailContext.show">+ <DrawerContent+ :title="$t('common.detail')"+ style="width: calc(100vw - 14rem)"+ >+ <TaskRunDetail+ v-if="taskRunDetailContext.taskRun"+ :key="taskRunDetailContext.taskRun.name"+ :task-run="taskRunDetailContext.taskRun"+ :database="getDatabaseForTaskRun(taskRunDetailContext.taskRun)"+ />+ </DrawerContent>+ </Drawer></template><script lang="ts" setup>-import {- ChevronDownIcon,- ChevronRightIcon,- DatabaseBackupIcon,-} from "lucide-vue-next";-import { NButton, NTimeline, NTimelineItem, NTooltip } from "naive-ui";+import { ChevronDownIcon, ChevronRightIcon } from "lucide-vue-next";+import { NTimeline, NTimelineItem, NTooltip } from "naive-ui";import { computed, ref } from "vue";+import TaskRunDetail from "@/components/IssueV1/components/TaskRunSection/TaskRunDetail.vue";import TimestampDisplay from "@/components/misc/Timestamp.vue";import TaskStatus from "@/components/Rollout/kits/TaskStatus.vue";-import type {- Rollout,- Stage,- TaskRun,-} from "@/types/proto-es/v1/rollout_service_pb";+import { Drawer, DrawerContent } from "@/components/v2";+import { useCurrentProjectV1 } from "@/store";+import type { Stage, TaskRun } from "@/types/proto-es/v1/rollout_service_pb";import { TaskRun_Status } from "@/types/proto-es/v1/rollout_service_pb";import {+ databaseForTask,extractDatabaseResourceName,extractInstanceResourceName,} from "@/utils";import { useResourcePoller } from "../../../logic/poller";-import TaskRunRollbackDrawer from "../TaskRunRollbackDrawer.vue";-import type { RollbackableTaskRun } from "./composables/useRollbackableTasks";import { useTaskNavigation } from "./composables/useTaskNavigation";import {- getErrorPreview,getTaskNameFromTaskRun,getTaskRunDuration,getTimelineType,mapTaskRunStatusToTaskStatus,} from "./composables/useTaskRunUtils";+import StageTaskRunsRollback from "./StageTaskRunsRollback.vue";const props = withDefaults(defineProps<{stage: Stage | null | undefined;taskRuns: TaskRun[];- rollout: Rollout;- rollbackableTaskRuns: RollbackableTaskRun[];isInline?: boolean;}>(),{@@ -186,15 +175,19 @@ const props = withDefaults(});-const emit = defineEmits<{- (event: "click-task-run", taskRun: TaskRun): void;-}>();-+const { project } = useCurrentProjectV1();const isCollapsed = ref(false);-const showRollbackDrawer = ref(false);const { navigateToTaskDetail } = useTaskNavigation();const { lastRefreshTime } = useResourcePoller();+// Drawer state for task run detail+const taskRunDetailContext = ref<{+ show: boolean;+ taskRun?: TaskRun;+}>({+ show: false,+});+// In sidebar mode (not inline), always show expandedconst isExpanded = computed(() => !props.isInline || !isCollapsed.value);@@ -213,6 +206,9 @@ const isLoading = computed(() => lastRefreshTime.value === 0 && stageTaskRuns.value.length === 0);+// Maximum number of task runs to display in the timeline+const MAX_DISPLAY_ITEMS = 50;+// Sort by updateTime descending (most recent first)const sortedTaskRuns = computed(() => {return [...stageTaskRuns.value].sort((a, b) => {@@ -222,28 +218,44 @@ const sortedTaskRuns = computed(() => {});});+// Limit displayed items for performance+const displayedTaskRuns = computed(() =>+ sortedTaskRuns.value.slice(0, MAX_DISPLAY_ITEMS)+);+const getTaskFromTaskRun = (taskRun: TaskRun) => {const taskName = getTaskNameFromTaskRun(taskRun.name);return props.stage?.tasks.find((t) => t.name === taskName);};-const getTaskTargetDisplay = (- taskRun: TaskRun-): { instance: string; database: string } => {- const task = getTaskFromTaskRun(taskRun);- const target = task?.target;-- if (!target) {- return {- instance: "",- database: taskRun.name.split("/").pop() || "unknown",- };+// Pre-compute display data for displayed task runs to avoid repeated calls in template+const taskRunDisplayMap = computed(() => {+ const map = new Map<string, { instance: string; database: string }>();+ for (const taskRun of displayedTaskRuns.value) {+ const task = getTaskFromTaskRun(taskRun);+ const target = task?.target;+ if (!target) {+ map.set(taskRun.name, {+ instance: "",+ database: taskRun.name.split("/").pop() || "unknown",+ });+ } else {+ map.set(taskRun.name, {+ instance: extractInstanceResourceName(target) || "",+ database: extractDatabaseResourceName(target).databaseName || "unknown",+ });+ }}+ return map;+});- return {- instance: extractInstanceResourceName(target) || "",- database: extractDatabaseResourceName(target).databaseName || "unknown",- };+const getTaskTargetDisplay = (taskRun: TaskRun) => {+ return (+ taskRunDisplayMap.value.get(taskRun.name) ?? {+ instance: "",+ database: "unknown",+ }+ );};const handleClickTarget = (taskRun: TaskRun) => {@@ -253,7 +265,16 @@ const handleClickTarget = (taskRun: TaskRun) => {}};-const handleClickTaskRun = (taskRun: TaskRun) => {- emit("click-task-run", taskRun);+// Get database for a task run (used by TaskRunDetail in drawer)+const getDatabaseForTaskRun = (taskRun: TaskRun) => {+ const task = getTaskFromTaskRun(taskRun);+ return task ? databaseForTask(project.value, task) : undefined;+};++const showDetail = (taskRun: TaskRun) => {+ taskRunDetailContext.value = {+ show: true,+ taskRun,+ };};</script>diff --git a/frontend/src/components/Plan/components/RolloutView/v2/TaskItem.vue b/frontend/src/components/Plan/components/RolloutView/v2/TaskItem.vueindex e2da144e70..8a429a1e3c 100644--- a/frontend/src/components/Plan/components/RolloutView/v2/TaskItem.vue+++ b/frontend/src/components/Plan/components/RolloutView/v2/TaskItem.vue@@ -62,13 +62,6 @@<LoaderCircleIcon class="w-3 h-3 animate-spin" />{{ timingDisplay }}</span>- <!-- Completed duration -->- <span- v-else-if="timingDisplay"- class="text-xs text-gray-600"- >- {{ timingDisplay }}- </span></div></div>diff --git a/frontend/src/components/Plan/components/RolloutView/v2/composables/useTaskRunUtils.ts b/frontend/src/components/Plan/components/RolloutView/v2/composables/useTaskRunUtils.tsindex f729c95705..099d7c4d54 100644--- a/frontend/src/components/Plan/components/RolloutView/v2/composables/useTaskRunUtils.ts+++ b/frontend/src/components/Plan/components/RolloutView/v2/composables/useTaskRunUtils.ts@@ -60,16 +60,6 @@ export const getTimelineType = (status: TaskRun_Status): TimelineType => {}};-/**- * Get first line preview of error detail, truncated to maxLength.- */-export const getErrorPreview = (detail: string, maxLength = 50): string => {- const firstLine = detail.split("\n")[0];- return firstLine.length > maxLength- ? `${firstLine.substring(0, maxLength)}...`- : firstLine;-};-/*** Format duration in milliseconds to human-readable string.* - >= 1h: "Xh Ym"diff --git a/frontend/src/components/Plan/logic/poller/poller.ts b/frontend/src/components/Plan/logic/poller/poller.tsindex 4931d76108..75d45f00cf 100644--- a/frontend/src/components/Plan/logic/poller/poller.ts+++ b/frontend/src/components/Plan/logic/poller/poller.ts@@ -33,6 +33,7 @@ import {refreshPlanCheckRuns,refreshRollout,refreshTaskRuns,+ type TaskRunScope,} from "./utils";type ResourceType = "plan" | "planCheckRuns" | "issue" | "rollout" | "taskRuns";@@ -58,6 +59,14 @@ export const provideResourcePoller = () => {const { isCreating, plan, planCheckRuns, taskRuns, issue, rollout, events } =usePlanContext();+ // Extract stage/task scope from route params for scoped taskRuns polling+ const taskRunScope = computed<TaskRunScope | undefined>(() => {+ const stageId = route.params.stageId as string | undefined;+ const taskId = route.params.taskId as string | undefined;+ if (!stageId) return undefined;+ return { stageId, taskId };+ });+// Consolidated state managementconst pollerState = ref({isRefreshing: false,@@ -106,7 +115,12 @@ export const provideResourcePoller = () => {canRefresh: () => !!rollout?.value && !!taskRuns,refresh: () => {if (!rollout.value) return Promise.resolve();- return refreshTaskRuns(rollout.value, project.value, taskRuns);+ return refreshTaskRuns(+ rollout.value,+ project.value,+ taskRuns,+ taskRunScope.value+ );},},};@@ -291,6 +305,21 @@ export const provideResourcePoller = () => {{ deep: true });+ // Watch for taskRunScope changes (stage/task navigation) and refresh taskRuns+ watch(+ taskRunScope,+ async (newScope, oldScope) => {+ const scopeChanged =+ newScope?.stageId !== oldScope?.stageId ||+ newScope?.taskId !== oldScope?.taskId;++ if (scopeChanged && resourceStrategies.taskRuns.canRefresh()) {+ await resourceStrategies.taskRuns.refresh();+ }+ },+ { deep: true }+ );+// Watch for plan issue/rollout changes on plan pageswatch(() => ({ issue: plan.value?.issue, rollout: plan.value?.rollout }),diff --git a/frontend/src/components/Plan/logic/poller/utils.ts b/frontend/src/components/Plan/logic/poller/utils.tsindex a9bb9631ff..ae45198336 100644--- a/frontend/src/components/Plan/logic/poller/utils.ts+++ b/frontend/src/components/Plan/logic/poller/utils.ts@@ -70,17 +70,31 @@ export const refreshIssue = async (issue: Ref<Issue>): Promise<void> => {issue.value = newIssue;};+export interface TaskRunScope {+ stageId?: string;+ taskId?: string;+}+export const refreshTaskRuns = async (rollout: Rollout,project: Project,- taskRuns: Ref<TaskRun[]>+ taskRuns: Ref<TaskRun[]>,+ scope?: TaskRunScope): Promise<void> => {if (!hasProjectPermissionV2(project, "bb.taskRuns.list")) {return;}+ // Build parent path based on scope+ // - No scope: fetch all task runs for the rollout+ // - stageId only: fetch task runs for a specific stage+ // - stageId + taskId: fetch task runs for a specific task+ const stagePart = scope?.stageId ?? "-";+ const taskPart = scope?.taskId ?? "-";+ const parent = `${rollout.name}/stages/${stagePart}/tasks/${taskPart}`;+const request = create(ListTaskRunsRequestSchema, {- parent: `${rollout.name}/stages/-/tasks/-`,+ parent,});const response = await rolloutServiceClientConnect.listTaskRuns(request);taskRuns.value = response.taskRuns;diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 62b7cac4d0..001e87d718 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -320,6 +320,7 @@"scheduled-time": "Scheduled time","scheduled-at": "Scheduled at","run-history": "Run History",+ "only-showing-latest-n-runs": "Only showing latest {n} runs","select-scheduled-time": "Select scheduled time","error": {"scheduled-time-must-be-in-the-future": "Scheduled time must be in the future"diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 2db616c68c..30380de0fe 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -320,6 +320,7 @@"scheduled-time": "Hora programada","scheduled-at": "Programado en","run-history": "Historial de ejecución",+ "only-showing-latest-n-runs": "Solo se muestran las últimas {n} ejecuciones","select-scheduled-time": "Seleccionar hora programada","error": {"scheduled-time-must-be-in-the-future": "La hora programada debe ser en el futuro"diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex 330d17130e..d0e88c317b 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -320,6 +320,7 @@"scheduled-time": "予定時刻","scheduled-at": "予定日時","run-history": "実行履歴",+ "only-showing-latest-n-runs": "最新の {n} 実行のみを表示","select-scheduled-time": "予定時刻を選択してください","error": {"scheduled-time-must-be-in-the-future": "スケジュール時間は将来の時間である必要があります"diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex 7c5d901820..f5874852c9 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -320,6 +320,7 @@"scheduled-time": "Thời gian đã lên lịch","scheduled-at": "Đã lên lịch tại","run-history": "Lịch sử chạy",+ "only-showing-latest-n-runs": "Chỉ hiển thị các lần chạy {n} mới nhất","select-scheduled-time": "Chọn thời gian đã lên lịch","error": {"scheduled-time-must-be-in-the-future": "Thời gian dự kiến phải ở trong tương lai"diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex b7500d7235..464ac73b32 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -320,6 +320,7 @@"scheduled-time": "计划时间","scheduled-at": "计划于","run-history": "执行历史",+ "only-showing-latest-n-runs": "仅显示最近 {n} 条记录","select-scheduled-time": "选择计划时间","error": {"scheduled-time-must-be-in-the-future": "计划时间必须是将来的时间"