전략편집기 기준값 보조지표 설정값 동기화

This commit is contained in:
Macbook
2026-05-28 09:20:06 +09:00
parent 9137864f48
commit e2816b037f
18 changed files with 710 additions and 153 deletions
+21 -3
View File
@@ -67,6 +67,9 @@ let _loadPromise: Promise<AllSettings> | null = null;
let _visualCache: VisualCache | null = null;
let _visualLoadPromise: Promise<VisualCache> | null = null;
/** 로그인 세션별 1회만 DB 로드 — 페이지 전환 시 캐시 유지 */
let _loadedSessionKey: number | null = null;
function ensureLoaded(): Promise<AllSettings> {
if (_cache !== null) return Promise.resolve(_cache);
if (_loadPromise) return _loadPromise;
@@ -110,6 +113,7 @@ export function invalidateIndicatorSettingsCache() {
_loadPromise = null;
_visualCache = null;
_visualLoadPromise = null;
_loadedSessionKey = null;
}
// ─────────────────────────────────────────────────────────────────────────────
@@ -120,11 +124,24 @@ export function useIndicatorSettings(sessionKey = 0) {
() => _cache !== null && _visualCache !== null,
);
// 로그인/로그아웃 시 지표 설정 재로드
// 로그인/로그아웃 시 지표 설정 재로드 (페이지 전환만으로는 캐시 유지)
useEffect(() => {
setSettingsLoaded(false);
invalidateIndicatorSettingsCache();
const unsub = subscribeIndicatorSettings(() => setSettingsRevision(r => r + 1));
const cacheWarm = _loadedSessionKey === sessionKey
&& _cache !== null
&& _visualCache !== null;
if (cacheWarm) {
setSettingsLoaded(true);
return unsub;
}
if (_loadedSessionKey !== sessionKey) {
invalidateIndicatorSettingsCache();
}
setSettingsLoaded(false);
Promise.all([
ensureLoaded().catch(err =>
console.error('[useIndicatorSettings] params load failed', err),
@@ -133,6 +150,7 @@ export function useIndicatorSettings(sessionKey = 0) {
console.error('[useIndicatorSettings] visual load failed', err),
),
]).then(() => {
_loadedSessionKey = sessionKey;
setSettingsLoaded(true);
setSettingsRevision(r => r + 1);
});