Skip to content

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

fix(frontend): clean up temp edit statement state when they are no more valid (#6446)

Liu Ji63a7be5b8ec6
diff --git a/frontend/src/components/Issue/IssueTaskStatementPanel.vue b/frontend/src/components/Issue/IssueTaskStatementPanel.vue
index 2f07787ce6..8a01921d7b 100644
--- a/frontend/src/components/Issue/IssueTaskStatementPanel.vue
+++ b/frontend/src/components/Issue/IssueTaskStatementPanel.vue
@@ -290,9 +290,19 @@ const useTempEditState = (state: LocalState) => {
},
{ immediate: true }
);
+
+ const reset = () => {
+ stopWatching && stopWatching();
+
+ if (!create.value) {
+ stopWatching = startWatching();
+ }
+ };
+
+ return reset;
};
-useTempEditState(state);
+const resetTempEditState = useTempEditState(state);
const getOrFetchSheetStatementByName = async (
sheetName: string | undefined
@@ -449,6 +459,7 @@ const saveEdit = async () => {
if (!selectedDatabase.value) {
return;
}
+ resetTempEditState();
if (allowFormatOnSave.value && formatOnSave.value) {
editorRef.value?.formatEditorContent();
}
@@ -508,6 +519,7 @@ const handleUploadFile = async (event: Event, tick: (p: number) => void) => {
});
state.isUploadingFile = false;
+ resetTempEditState();
updateSheetId(sheetV1Store.getSheetUid(sheet.name));
await updateStatement(statement);
state.editing = false;
diff --git a/frontend/src/main.ts b/frontend/src/main.ts
index 429a62a4ee..b0d8ae2e69 100644
--- a/frontend/src/main.ts
+++ b/frontend/src/main.ts
@@ -112,7 +112,7 @@ axios.interceptors.response.use(
}
}
- if (error.response.data.message && !isSilent()) {
+ if (error.response.data?.message && !isSilent()) {
pushNotification({
module: "bytebase",
style: "CRITICAL",
diff --git a/frontend/src/store/modules/v1/sheet.ts b/frontend/src/store/modules/v1/sheet.ts
index 26e15f366a..73ff77e783 100644
--- a/frontend/src/store/modules/v1/sheet.ts
+++ b/frontend/src/store/modules/v1/sheet.ts
@@ -18,6 +18,8 @@ interface SheetState {
sheetByName: Map<string, Sheet>;
}
+const REQUEST_CACHE = new Map<string /* uid */, Promise<Sheet | undefined>>();
+
export const useSheetV1Store = defineStore("sheet_v1", {
state: (): SheetState => ({
sheetByName: new Map<string, Sheet>(),
@@ -161,15 +163,34 @@ export const useSheetV1Store = defineStore("sheet_v1", {
return sheet;
}
- try {
- const sheet = await sheetServiceClient.getSheet({
- name: `${projectNamePrefix}-/${sheetNamePrefix}${uid}`,
- });
- this.sheetByName.set(sheet.name, sheet);
- return sheet;
- } catch {
- return;
+ const cached = REQUEST_CACHE.get(String(uid));
+ if (cached) {
+ return cached;
}
+
+ const runner = async () => {
+ try {
+ const sheet = await sheetServiceClient.getSheet({
+ name: `${projectNamePrefix}-/${sheetNamePrefix}${uid}`,
+ });
+ return sheet;
+ } catch {
+ return;
+ }
+ };
+
+ const request = runner();
+ request.then((sheet) => {
+ if (sheet) {
+ this.sheetByName.set(sheet.name, sheet);
+ } else {
+ // If the request failed (e.g., "Too many requests")
+ // Remove the cache entry so we can retry when needed.
+ REQUEST_CACHE.delete(String(uid));
+ }
+ });
+ REQUEST_CACHE.set(String(uid), request);
+ return request;
},
async getOrFetchSheetByName(name: string) {
const storedSheet = this.sheetByName.get(name);