Reduce server console polling load

This commit is contained in:
npc0-hue
2026-09-07 19:49:20 +08:00
parent 1b583f3ca6
commit 4ab7bb820d
10 changed files with 110 additions and 25 deletions
+9
View File
@@ -17,6 +17,7 @@ import { defaultThemeBackgroundId, defaultThemePaletteId, loadThemeState } from
const sessionTokenStorageKey = "platform-web.session.apiToken";
const localFallbackEnabled = readWebRuntimeEnv().enableLocalAuthFallback;
let currentUserLoadPromise: Promise<CurrentUserView | null> | null = null;
export const localFallbackUser: CurrentUserView = {
id: "local-server-operator",
@@ -57,6 +58,14 @@ export interface SessionState {
}
export async function loadCurrentUser(): Promise<CurrentUserView | null> {
if (currentUserLoadPromise) return currentUserLoadPromise;
currentUserLoadPromise = loadCurrentUserOnce().finally(() => {
currentUserLoadPromise = null;
});
return currentUserLoadPromise;
}
async function loadCurrentUserOnce(): Promise<CurrentUserView | null> {
const storedToken = readStoredSessionToken();
setPlatformApiSessionToken(storedToken);
try {