Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Exclude slash usage statistics from settings save failures https://github.com/siyuan-note/siyuan/issues/20271

Daniel0e18b05f5736
diff --git a/app/src/config/setting/pending.test.ts b/app/src/config/setting/pending.test.ts
index 815e0b1bb3..74b1317712 100644
--- a/app/src/config/setting/pending.test.ts
+++ b/app/src/config/setting/pending.test.ts
@@ -59,3 +59,19 @@ test("reset waits for graph writes and rejects failed graph saves", async () =>
await assert.rejects(flush);
}
});
+
+test("slash usage failures do not affect preference saves", async () => {
+ for (const result of [Promise.resolve({code: -1}), Promise.reject(new Error("offline"))]) {
+ const before = settingSaveFailures();
+ await trackSettingRequest("/api/storage/setLocalStorageVal", result, true).catch(() => {});
+ await flushSettingSaves(before);
+ assert.equal(settingSaveFailures(), before);
+ }
+ for (const path of ["/api/storage/setLocalStorage", "/api/storage/setLocalStorageVal", "/api/storage/removeLocalStorageVal", "/api/storage/removeLocalStorageVals"]) {
+ const before = settingSaveFailures();
+ await trackSettingRequest(path, Promise.resolve({code: -1}));
+ await assert.rejects(flushSettingSaves(before));
+ }
+ trackSettingRequest("/api/storage/setLocalStorageOther", new Promise(() => {}));
+ await flushSettingSaves();
+});
diff --git a/app/src/config/setting/pending.ts b/app/src/config/setting/pending.ts
index ef998c55a7..ffa8b033a2 100644
--- a/app/src/config/setting/pending.ts
+++ b/app/src/config/setting/pending.ts
@@ -16,8 +16,9 @@ export const trackSettingSave = <T>(promise: Promise<T>): Promise<T> => {
return promise;
};
-export const trackSettingRequest = <T>(url: string, promise: Promise<T>): Promise<T> =>
- /^\/api\/(setting\/(set|patch)|asset\/setOCRConfig$|storage\/(set|remove)LocalStorage|system\/set|graph\/(setGraphConf|resetGraph|resetLocalGraph|getGraph|getLocalGraph)$)/.test(url)
+export const trackSettingRequest = <T>(url: string, promise: Promise<T>, usageStatistics = false): Promise<T> =>
+ !usageStatistics &&
+ /^\/api\/(setting\/(set|patch)|asset\/setOCRConfig$|storage\/(setLocalStorage|setLocalStorageVal|removeLocalStorageVal|removeLocalStorageVals)$|system\/set|graph\/(setGraphConf|resetGraph|resetLocalGraph|getGraph|getLocalGraph)$)/.test(url)
? trackSettingSave(promise) : promise;
export const flushSettingSaves = async (previousFailures = failures) => {
diff --git a/app/src/util/fetch.ts b/app/src/util/fetch.ts
index ca50be44a4..78227a8371 100644
--- a/app/src/util/fetch.ts
+++ b/app/src/util/fetch.ts
@@ -78,7 +78,7 @@ export const fetchPost = ((
return response.text();
}
}
- }), signal, timeout))).then((response: IWebSocketData) => {
+ }), signal, timeout), url === "/api/storage/setLocalStorageVal" && data?.key === Constants.LOCAL_SLASH_USAGE)).then((response: IWebSocketData) => {
if (failCallback && url === "/api/file/getFile" && isGetFile202) {
failCallback(response);
return;
@@ -150,7 +150,7 @@ export const fetchSyncPost = (async (url: string, data?: any, headers?: Record<s
processMessage(res2);
}
return res2;
- }));
+ }), url === "/api/storage/setLocalStorageVal" && data?.key === Constants.LOCAL_SLASH_USAGE);
}) as FetchSyncPost<IWebSocketData>;
export const fetchGet = ((url: string, cb: (response: IWebSocketData | IObject | string) => void) => {