Skip to content

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

refactor: simplify sheet store by removing raw parameter (#18290)

boojack7d7fffed6a3d
diff --git a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
index 123f53bb4e..f067c91148 100644
--- a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
+++ b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
@@ -181,7 +181,6 @@ import { ExpandIcon } from "lucide-vue-next";
import { NButton, NTooltip, useDialog } from "naive-ui";
import { computed, reactive, ref, toRef, watch } from "vue";
import { useI18n } from "vue-i18n";
-import { useRoute } from "vue-router";
import { BBAttention, BBModal } from "@/bbkit";
import { ErrorList } from "@/components/IssueV1/components/common";
import {
@@ -235,7 +234,6 @@ const props = defineProps<{
}>();
const { t } = useI18n();
-const route = useRoute();
const context = useIssueContext();
const { events, isCreating, issue, selectedTask } = context;
const { project } = useCurrentProjectV1();
@@ -274,11 +272,6 @@ const statementTitle = computed(() => {
const { markers } = useSQLAdviceMarkers(context, toRef(props, "advices"));
const allowEditStatementWhenCreating = computed(() => {
- if (route.query.sheetId) {
- // Not allowed to edit pre-generated sheets
- // E.g., rollback DML
- return false;
- }
// Do not allow to edit statement for the plan with release source.
if (
(
diff --git a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunDetail.vue b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunDetail.vue
index 54963a2c50..167545fee9 100644
--- a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunDetail.vue
+++ b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunDetail.vue
@@ -77,7 +77,7 @@ watch(
async () => {
// Prepare the sheet data from task run.
if (props.taskRun.sheet) {
- await sheetStore.getOrFetchSheetByName(props.taskRun.sheet, "FULL");
+ await sheetStore.getOrFetchSheetByName(props.taskRun.sheet);
}
},
{ immediate: true }
diff --git a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunTable.vue b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunTable.vue
index 30e06c6257..8ae41ffdbc 100644
--- a/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunTable.vue
+++ b/frontend/src/components/IssueV1/components/TaskRunSection/TaskRunTable.vue
@@ -68,8 +68,7 @@ const { selectedTask } = useIssueContext();
const sheet = computedAsync(async () => {
return useSheetV1Store().getOrFetchSheetByName(
- sheetNameOfTaskV1(selectedTask.value),
- "FULL"
+ sheetNameOfTaskV1(selectedTask.value)
);
});
diff --git a/frontend/src/components/Plan/components/RolloutView/v2/TaskList.vue b/frontend/src/components/Plan/components/RolloutView/v2/TaskList.vue
index 7a32067e70..d6cc71f8b7 100644
--- a/frontend/src/components/Plan/components/RolloutView/v2/TaskList.vue
+++ b/frontend/src/components/Plan/components/RolloutView/v2/TaskList.vue
@@ -33,7 +33,7 @@
<!-- Show More button -->
<div
v-if="hasMoreTasks"
- class="flex justify-center py-4"
+ class="flex justify-center"
>
<button
class="px-4 py-2 text-sm text-blue-600 hover:text-blue-700 hover:bg-blue-50 rounded-md transition-colors"
@@ -51,7 +51,6 @@ import { computed, ref, watch } from "vue";
import { usePlanContextWithRollout } from "@/components/Plan/logic/context";
import type { Rollout, Stage } from "@/types/proto-es/v1/rollout_service_pb";
import { Task_Status } from "@/types/proto-es/v1/rollout_service_pb";
-import { useSheetPreload } from "./composables/useSheetPreload";
import { useTaskCollapse } from "./composables/useTaskCollapse";
import { useTaskSelection } from "./composables/useTaskSelection";
import { DEFAULT_PAGE_SIZE } from "./constants";
@@ -106,14 +105,7 @@ const loadMoreTasks = () => {
);
};
-const { expandedTaskIds, isTaskExpanded, toggleExpand } =
- useTaskCollapse(filteredTasks);
-
-// Prefetch sheets for expanded tasks only (statements not shown in collapsed view)
-const expandedTasks = computed(() =>
- visibleTasks.value.filter((task) => expandedTaskIds.value.has(task.name))
-);
-useSheetPreload(() => expandedTasks.value);
+const { isTaskExpanded, toggleExpand } = useTaskCollapse(filteredTasks);
const {
selectedTasks,
diff --git a/frontend/src/components/Plan/components/RolloutView/v2/composables/useSheetPreload.ts b/frontend/src/components/Plan/components/RolloutView/v2/composables/useSheetPreload.ts
deleted file mode 100644
index 64447e8c67..0000000000
--- a/frontend/src/components/Plan/components/RolloutView/v2/composables/useSheetPreload.ts
+++ /dev/null
@@ -1,44 +0,0 @@
-import { ref, watch } from "vue";
-import { useSheetV1Store } from "@/store";
-import type { Task } from "@/types/proto-es/v1/rollout_service_pb";
-import { sheetNameOfTaskV1 } from "@/utils";
-
-/**
- * Prefetches sheets for the given tasks in parallel.
- */
-export const useSheetPreload = (tasks: () => Task[]) => {
- const sheetStore = useSheetV1Store();
- const fetchedSheets = ref(new Set<string>());
-
- watch(
- tasks,
- (currentTasks) => {
- // Extract unique sheet names
- const sheetNames = new Set<string>();
- for (const task of currentTasks) {
- const sheetName = sheetNameOfTaskV1(task);
- if (sheetName) {
- sheetNames.add(sheetName);
- }
- }
-
- // Filter to only unfetched sheets
- const newSheets = Array.from(sheetNames).filter(
- (name) => !fetchedSheets.value.has(name)
- );
-
- if (newSheets.length === 0) return;
-
- // Batch fetch in parallel
- Promise.all(
- newSheets.map((name) => sheetStore.getOrFetchSheetByName(name, "BASIC"))
- );
-
- // Mark as fetched
- for (const name of newSheets) {
- fetchedSheets.value.add(name);
- }
- },
- { immediate: true }
- );
-};
diff --git a/frontend/src/components/Plan/logic/initialize/create.ts b/frontend/src/components/Plan/logic/initialize/create.ts
index 272c5fb682..627d9db9e9 100644
--- a/frontend/src/components/Plan/logic/initialize/create.ts
+++ b/frontend/src/components/Plan/logic/initialize/create.ts
@@ -1,8 +1,8 @@
import { create as createProto } from "@bufbuild/protobuf";
-import { cloneDeep, head, includes } from "lodash-es";
+import { head, includes } from "lodash-es";
import { v4 as uuidv4 } from "uuid";
import { useRoute } from "vue-router";
-import { useProjectV1Store, useSheetV1Store } from "@/store";
+import { useProjectV1Store } from "@/store";
import { projectNamePrefix } from "@/store/modules/v1/common";
import type { IssueType } from "@/types";
import {
@@ -17,7 +17,7 @@ import {
PlanSchema,
} from "@/types/proto-es/v1/plan_service_pb";
import type { Project } from "@/types/proto-es/v1/project_service_pb";
-import { extractSheetUID, getSheetStatement, setSheetStatement } from "@/utils";
+import { extractSheetUID, setSheetStatement } from "@/utils";
import { sheetNameForSpec, targetsForSpec } from "../plan";
import { getLocalSheetByName, getNextLocalSheetUID } from "../sheet";
import { extractInitialSQLFromQuery } from "./util";
@@ -112,28 +112,10 @@ export const buildPlan = async (params: CreatePlanParams) => {
const buildSpecForTargetsV1 = async (
targets: string[],
- { project, template, query }: CreatePlanParams,
+ { project, template }: CreatePlanParams,
sheetUID?: string
) => {
- let sheet = `${project.name}/sheets/${sheetUID ?? getNextLocalSheetUID()}`;
- if (query.sheetId) {
- const remoteSheet = await useSheetV1Store().getOrFetchSheetByUID(
- query.sheetId,
- "FULL"
- );
- if (remoteSheet) {
- // make a local copy for remote sheet for further editing
- console.debug(
- "copy remote sheet to local for further editing",
- remoteSheet
- );
- const localSheet = getLocalSheetByName(sheet);
- localSheet.payload = cloneDeep(remoteSheet.payload);
- const statement = getSheetStatement(remoteSheet);
- setSheetStatement(localSheet, statement);
- sheet = remoteSheet.name;
- }
- }
+ const sheet = `${project.name}/sheets/${sheetUID ?? getNextLocalSheetUID()}`;
const spec = createProto(Plan_SpecSchema, {
id: uuidv4(),
diff --git a/frontend/src/components/Revision/RevisionDetailPanel.vue b/frontend/src/components/Revision/RevisionDetailPanel.vue
index 3ac9daa956..345932afac 100644
--- a/frontend/src/components/Revision/RevisionDetailPanel.vue
+++ b/frontend/src/components/Revision/RevisionDetailPanel.vue
@@ -96,7 +96,7 @@ watch(
}
// Prepare the sheet data from task run.
if (revision.sheet) {
- await sheetStore.getOrFetchSheetByName(revision.sheet, "FULL");
+ await sheetStore.getOrFetchSheetByName(revision.sheet);
}
}
state.loading = false;
diff --git a/frontend/src/store/modules/v1/sheet.ts b/frontend/src/store/modules/v1/sheet.ts
index 93e4965dfa..29b44ee1a0 100644
--- a/frontend/src/store/modules/v1/sheet.ts
+++ b/frontend/src/store/modules/v1/sheet.ts
@@ -15,29 +15,20 @@ import {
} from "@/types/proto-es/v1/sheet_service_pb";
import { extractSheetUID, getSheetStatement } from "@/utils";
-export type SheetView = "FULL" | "BASIC";
-type SheetCacheKey = [string /* uid */, SheetView];
-
export const useSheetV1Store = defineStore("sheet_v1", () => {
- const cacheByUID = useCache<SheetCacheKey, Sheet | undefined>(
- "bb.sheet.by-uid"
- );
+ const cacheByUID = useCache<[string], Sheet | undefined>("bb.sheet.by-uid");
// Utilities
const removeLocalSheet = (name: string) => {
const uid = extractSheetUID(name);
if (uid.startsWith("-")) {
- cacheByUID.invalidateEntity([uid, "FULL"]);
+ cacheByUID.invalidateEntity([uid]);
}
};
- const setCache = (sheet: Sheet, view: SheetView) => {
+ const setCache = (sheet: Sheet) => {
const uid = extractSheetUID(sheet.name);
if (uid === String(UNKNOWN_ID)) return;
- if (view === "FULL") {
- // A FULL version should override BASIC version
- cacheByUID.invalidateEntity([uid, "BASIC"]);
- }
- cacheByUID.setEntity([uid, view], sheet);
+ cacheByUID.setEntity([uid], sheet);
};
// CRUD
@@ -63,60 +54,36 @@ export const useSheetV1Store = defineStore("sheet_v1", () => {
sheet: fullSheet,
});
const response = await sheetServiceClientConnect.createSheet(request);
- setCache(response, "FULL");
+ setCache(response);
if (sheet.name) {
removeLocalSheet(sheet.name);
}
return response;
};
- /**
- *
- * @param uid
- * @param view default undefined to any (FULL -> BASIC)
- * @returns
- */
- const getSheetByUID = (uid: string, view?: SheetView) => {
- if (view === undefined) {
- return (
- cacheByUID.getEntity([uid, "FULL"]) ??
- cacheByUID.getEntity([uid, "BASIC"])
- );
- }
- return cacheByUID.getEntity([uid, view]);
+ const getSheetByUID = (uid: string) => {
+ return cacheByUID.getEntity([uid]);
};
- const getSheetRequestByUID = (uid: string, view?: SheetView) => {
- if (view === undefined) {
- return (
- cacheByUID.getRequest([uid, "FULL"]) ??
- cacheByUID.getRequest([uid, "BASIC"])
- );
- }
- return cacheByUID.getRequest([uid, view]);
+ const getSheetRequestByUID = (uid: string) => {
+ return cacheByUID.getRequest([uid]);
};
- /**
- *
- * @param name
- * @param view default undefined to any (FULL -> BASIC)
- * @returns
- */
- const getSheetByName = (name: string, view?: SheetView) => {
+ const getSheetByName = (name: string) => {
const uid = extractSheetUID(name);
if (!uid || uid === String(UNKNOWN_ID)) {
return undefined;
}
- return getSheetByUID(uid, view);
+ return getSheetByUID(uid);
};
- const fetchSheetByName = async (name: string, view: SheetView) => {
+ const fetchSheetByName = async (name: string) => {
const uid = extractSheetUID(name);
if (uid.startsWith("-") || !uid) {
return undefined;
}
try {
- console.debug("[fetchSheetByName]", name, view);
+ console.debug("[fetchSheetByName]", name);
const request = create(GetSheetRequestSchema, {
name,
- raw: view === "FULL",
+ raw: false,
});
const response = await sheetServiceClientConnect.getSheet(request);
return response;
@@ -124,34 +91,34 @@ export const useSheetV1Store = defineStore("sheet_v1", () => {
return undefined;
}
};
- const getOrFetchSheetByName = async (name: string, view?: SheetView) => {
+ const getOrFetchSheetByName = async (name: string) => {
const uid = extractSheetUID(name);
if (uid.startsWith("-") || !uid) {
return undefined;
}
- const entity = getSheetByUID(uid, view);
+ const entity = getSheetByUID(uid);
if (entity) {
return entity;
}
- const request = getSheetRequestByUID(uid, view);
+ const request = getSheetRequestByUID(uid);
if (request) {
return request;
}
- const promise = fetchSheetByName(name, view ?? "BASIC");
- cacheByUID.setRequest([uid, view ?? "BASIC"], promise);
+ const promise = fetchSheetByName(name);
+ cacheByUID.setRequest([uid], promise);
promise.then((sheet) => {
if (!sheet) {
// If the request failed
// remove the request cache entry so we can retry when needed.
- cacheByUID.invalidateRequest([uid, view ?? "BASIC"]);
+ cacheByUID.invalidateRequest([uid]);
return;
}
});
return promise;
};
- const getOrFetchSheetByUID = async (uid: string, view?: SheetView) => {
- return getOrFetchSheetByName(`projects/-/sheets/${uid}`, view);
+ const getOrFetchSheetByUID = async (uid: string) => {
+ return getOrFetchSheetByName(`projects/-/sheets/${uid}`);
};
const patchSheetContent = async (sheet: Partial<Sheet>) => {
@@ -171,7 +138,7 @@ export const useSheetV1Store = defineStore("sheet_v1", () => {
updateMask: { paths: ["content"] },
});
const response = await sheetServiceClientConnect.updateSheet(request);
- setCache(response, "FULL");
+ setCache(response);
return response;
};
@@ -186,17 +153,14 @@ export const useSheetV1Store = defineStore("sheet_v1", () => {
};
});
-export const useSheetStatementByUID = (
- uid: MaybeRef<string>,
- view?: MaybeRef<SheetView | undefined>
-) => {
+export const useSheetStatementByUID = (uid: MaybeRef<string>) => {
const store = useSheetV1Store();
watchEffect(async () => {
- await store.getOrFetchSheetByUID(unref(uid), unref(view));
+ await store.getOrFetchSheetByUID(unref(uid));
});
return computed(() => {
- const sheet = store.getSheetByUID(unref(uid), unref(view));
+ const sheet = store.getSheetByUID(unref(uid));
if (!sheet) return "";
return getSheetStatement(sheet);
});